An update of using Google Contacts API as server to server PHP application (2020)

An update of using Google Contacts API as server to server PHP application

Google changed its API console user interface so this article is just an update of the screenshots of this post.

Create a Google service account

  1. Login to your Google account.

  2. Create a project here.

    Create project

  3. Populate the "Project name" and click "CREATE" button:

    Create project window

  4. Wait until Google finished creating the project, you will be redirected to a new page (like the one shown below) once it is completed.

    Search for APIs and Services field

    Under "Search for APIs & Sevices" field type "contacts" and click "Contacts API" search result:

    Google APIs search result list

  5. You should be redirected to "Contacts API" page. Click the "ENABLE" button:

    Contacts API enable

  6. On "Contacts API" Overview page, click "CREATE CREDENTIALS" button at the right side:

    Create credetials

  7. You will be redirected to "Credentials" page. Select "Web server (e.g. node.js, Tomcat)" option from "Where will you be calling the API from?" field. Choose "Application data" from "What data will you be accessing?" field. Select "No, I’m not using them" option from "Are you planning to use this API with App Engine or Compute Engine?" field. Then click "What credentials do I need?" button:

    Create credentials page

  8. Populate the "Service account name" field. Click the "Role" dropdown menu, from the selection choose "Project" then "Editor". Click "Continue" button:

    Create credentials account

  9. You should be receiving a JSON file that contains private key of Google service account you've just created. Click "Ok" button of the popped alert box.

    Service account created alert box

    And you will be redirected to "Credentials" main page. Click the "Manage service accounts" link:

    Manage service account

  10. On "Service Accounts" page, click the "More actions" icon at the right of your Google service account and select "Edit" from the dropdown menu:

    Manage service account options

  11. A window will pop up. Click the "SHOW DOMAIN-WIDE DELEGATION" to expand.

    Service account details page

    Tick the "Enable G Suite Domain-wide Delegation" checkbox, populate the "Product name for the consent screen" text field and click "SAVE" button:

    Expanded service account details page

Delegate domain-wide authority to Google service account

  1. Login to your Google's suite or Google Apps with your account that has administrator role here.

  2. Click "Security" from your "Admin Console" page:

    Manage security

  3. You will be redirected to "Security" page, click "Advanced settings" to expand:

    Manage security page

  4. Still on "Security" page under "Advanced settings", click "Manage API client access" link:

    Manage security advanced settings

  5. You will be redirected to "Manage API client access" page. Open the JSON file that you received from creating your Google service account and copy the value of client_id:

    Client ID

  6. Paste the client_id that you copied to "Client Name" field and populate the "One or More API Scopes" with "":

    Manage security client access

    Note: If you want to add more API scopes check

  7. Click the "Authorize" button:

    Manage security client access saved

Follow the instructions under "Google Contacts API PHP application" here.

Note: After testing creating contact, you need to "Refresh" your Google Contacts to show the newly created contact:

Google Contacts output

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.