5

I'm having a simple problem while retrieving user's contact's images. So I make a request to

$url = 'https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=9999&oauth_token=' . $accessToken;

And then I get huge JSON from which I have extracted full name and email. Then I tried getting contact's image, and haven't had any success.

I get with all contacts, and everyone has following structure:

entry [id, updated, category, title, link, gd$email].

In the link section, I got four links, of which first two are some kind of link to an image content but I cannot retrieve it.

Any body had any success in doing this kind of work !?

Tnx alot!

BTW: If some data from my case is missing, please report and I'll add it too!

EDIT: I have also tried to reach the image with URL

 http://profiles.google.com/s2/photos/profile/" + userid + "?sz=" + size;

but the problem is I cannot get userId from contacts JSON.

Adrian
  • 1,499
  • 3
  • 19
  • 26
  • https://developers.google.com/google-apps/contacts/v3/#retrieving_a_contacts_photo why doesn't this work? Isn't "id" the contactID you need? – awaigand Oct 16 '13 at 12:18
  • the problem is I don't have an ID of contact, I have a field id in my JSON which has "http://www.google.com/m8/feeds/contacts/adrian.1358%40gmail.com/base/10161fe0e87a941" – Adrian Oct 16 '13 at 12:21
  • also in link part of the JSON, I have a link like "https://www.google.com/m8/feeds/photos/media/adrian.1358%40gmail.com/10161fe0e87a941/1B2M2Y8AsgTpgAmY7PhCfg" – Adrian Oct 16 '13 at 12:21
  • 1
    btw I tried visiting those links.. everytime I got an error.. I also tried putting access_token on the end, no luck either.. :/ – Adrian Oct 16 '13 at 12:23
  • you do know that you need to register in the API Console, you need to get some sort of authentification (Like an AccessToken via OAuth 2) etc.? Especially if you want to access non-public user data. In Accordance of https://developers.google.com/google-apps/contacts/v3/index#getting_started – awaigand Oct 16 '13 at 12:31
  • Any update on this issue ? I'm having an issue with the resolution of the images rather than getting them. any idea how to get higher res ones ? – Edward Ashak Apr 18 '16 at 14:29

2 Answers2

3

You must call the photo endpoint and append to it a valid access token as a query parameter.

Example:

https://www.google.com/m8/feeds/photos/media/name.surname%40gmail.com/0?access_token=ACCESS_TOKEN

Docs:

https://developers.google.com/google-apps/contacts/v3/#contact_photo_management

db80
  • 4,157
  • 1
  • 38
  • 38
-1

Make a request again if the mentioned tags are available as given below.

$add = new Google_HttpRequest("https://www.google.com/m8/feeds/contacts/default/full?alt=json&v=3.0&max-results=500&access_token='.$token->access_token");
$add->setRequestMethod("GET");
$add->setRequestHeaders(array('GData-Version' => '3.0', 'content-type' => 'application/atom+xml; charset=UTF-8; type=feed'));

$submit = $client->getIo()->authenticatedRequest($add);
$sub_response = $submit->getResponseBody();

$temp = json_decode($sub_response, true);

foreach ($temp['feed']['entry'] as $image) {
  $google_contact_id = $image['link'][2]['href'];
  if (isset($image['link'][0]['href'])) {
    $photo = new Google_HttpRequest($image['link'][0]['href']);
    $photo_val = $client->getIo()->authenticatedRequest($photo);

    $photo_return = $photo_val->getResponseBody();                       
    $imgData = base64_encode($photo_return);
    $pro_image = 'data:image/jpeg;base64, ' . $imgData . '';
  }
}
Andy Jones
  • 6,205
  • 4
  • 31
  • 47