Search code examples
phpxmlweb-servicesgoogle-apigoogle-contacts-api

Google Contacts Broadcast/Push/Notification/Hook API


I am looking for a way to receive notifications / broadcasts from google when a contact on googles side is edited, deleted or created.

I looked through the Google Contacts API documentation but could not find anything..

I think there must be a way, e.g. Android for sure does not poll for changes.


Solution

  • The Google Contacts API documentation doesn't mention anything about a web hook like the Google Calendar API has.

    I think that what you might have to do is the following:

    1. Set up a database to store your contact's info.
    2. Create a PHP script which will query Google Contacts for the contact's updated info a. Use PHP's curl function to connect to Google Contacts API query link. b. Set the script to send the credentials requested by Google Contacts API. c. Compare the contact's information read from the Google Contacts API against the information on that contact stored in your database. If the information is different then update your database.
    3. Set your script to run periodically:
      a. If using Linux - Set your server's Cron function to run the script at certain times.
      -or-
      b. If using Windows - Set Windows Task Scheduler to run the script (or a batch file and the script) at certain times.

    (1. see this link for a tutorial on setting up a MySql database with PHP http://www.w3schools.com/PHP/php_mysql_intro.asp)

    (2. a. see this link for a tutorial on PHP curl http://wiki.dreamhost.com/CURL_PHP_tutorial)

    (2. b. see this link for Google Contacts API details on querying a contact's info https://developers.google.com/google-apps/contacts/v3/#retrieving_contacts_using_query_parameters)

    (2. b. see this link for details on using OAuth in PHP, which will be needed to connect to Google Contacts API http://php.net/manual/en/book.oauth.php)

    (3. see this link for details on Linux cron http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/)

    (3. see this link for an example on how to run a PHP script with a batch file and Windows Task Scheduler http://www.codingforums.com/archive/index.php/t-198431.html)

    Sincerely,

    mnutsch