I am trying to retrieve the photo of a contact using Google Contacts API according to this document. The PHP Client library used is here. I get the code and user information successfully but failed to get the user's photo data.
The response I got is :
Photo query failed - invalid contact ID
.
This is the PHP code of the callback function that I'm using to get the user's photo data :
$client = new Google_Client();
$client->setClientId(GOOGLE_APP_CLIENT_ID);
$client->setClientSecret(GOOGLE_APP_CLIENT_SECRET);
$client->setRedirectUri(GOOGLE_APP_CLIENT_REDIRECT_URI);
$client->addScope("openid profile email https://www.google.com/m8/feeds");
// Create a OAuth 2 service instance
$oauth2 = new Google_Service_Oauth2($client);
// Get the access token using code.
if (isset($_GET['code'])) {
// Authenticate the code
$client->authenticate($_GET['code']);
$_SESSION['access_code'] = $client->getAccessToken();
// Set the access token
$client->setAccessToken($_SESSION['access_token']);
$temp_obj = $client->verifyIdToken();
....
// Get the user's info
$guser_info = $oauth2->userinfo->get();
// Get the contact id
$contact_id = $guser_info['id'];
// Get the user email
$user_email = $guser_info['email'];
// Make an authenticated request to the photo
$req = new Google_Http_Request("https://www.google.com/m8/feeds/photos/media/default/$contact_id");
// For replacing above line with the following also got the same result.
//$req = new Google_Http_Request("https://www.google.com/m8/feeds/photos/media/$user_email/$contact_id");
// Make an authenticated request
$val = $client->getAuth()->authenticatedRequest($req);
print_r($val->getResponseBody());// Get "Photo query failed - invalid contact ID"
} ...
I have enabled Contacts API
in the console project and added scope https://www.google.com/m8/feeds
.
Is the retrieved id different from Contact ID of the user or is there a way to get the user's Contact ID or something wrong in my code?
Any help or comments are appreciated.