I'm trying to retrieve my Google contacts photos using a JSON response. I figured out how to authenticate and how to retrieve the info that i need.
Now, i'm trying to display the contacts photo as well, and i know that the photo is located in this bit of the json response:
[link] => Array
(
[0] => Array
(
[rel] => http://schemas.google.com/contacts/2008/rel#photo
[type] => image/*
[href] => https://www.google.com/m8/feeds/photos/media/mymail%40gmail.com/{code}
[gd$etag] => "{code}"
)
)
Now, if I echo the href, and then add the access_token, the link looks like this ->
https://www.google.com/m8/feeds/photos/media/{{my-email-address}}/7473ab09b97a34?v=3.0?access_token={{my-access-token}}
And this results in a broken link. I've noticed tho that if i remove the ?ver=3
, the link actually works. Problem is: the ?ver=3 comes from the json response so i don't know how to remove it.
Now, i've tried to set the link as a variable, to remove the ?ver=3
, bur the links is still broken as i don't know where to find the {code}
needed for each contacts.
Any help? how can i solve this?
Thanks a lot
Based on the related question mentioned before ( return google contacts api v3 photo? ), perhaps deal with the JSON response like this:
foreach($output_array as $key=>$value){
if (isset($value['email'], $value['title'])) {
echo $value['email'].'<br/>';
echo $value['title'].'<br/>';
$photo = new Google_HttpRequest($value['hrefs'][0][0]);
$photo_val = $client->getIo()->authenticatedRequest($photo);
$photo_return = $photo_val->getResponseBody();
$imgData = base64_encode($photo_return);
echo "<img src= 'data:image/jpeg;base64, $imgData' />";
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.