如何使用PHP使用Google API获取用户'contactid' [英] How to get the user 'contactid' using google API using PHP
问题描述
我试图通过使用google API 3.0获取所有用户详细信息的用户联系人。
我可以通过用户的详细信息获得JSON响应。
$ url ='https:/ /www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$accesstoken;
结果是
[entry] =>数组
(
[0] =>数组
(
[id] =>数组
(
[$ t] => http ://www.google.com/m8/feeds/contacts/sfdhitdf1%40gmail.com/base/1
)
[gd $ etag] =>RXc7fTVSLit7I2A9XRZaEkoLRAw。
[updated] => Array
(
[$ t] => 2014-08-29T00:16:24.905Z
)
[ app $ edited] => Array
(
[xmlns $ app] => http://www.w3.org/2007/app
[$ t] => 2014 -08-29T00:16:24.905Z
)
[类别] =>数组
(
[0] => Array
(
[scheme] => http://schemas.google.com/g/2005#kind
[term] => http://schemas.google.com / contact / 2008#contact
)
)
[title] =>数组
(
[$ t] => abc
)
[link] =>数组
(
[0] =>数组
(
[rel] => http://schemas.google.com/contacts/2008/rel#photo
[type] =>图片
[href] => https://www.google.com/m8/feeds/photos/media/sachdfwdfd%40gmail.com/1?v=3.0
[gd $ etag] =>VWVIH3oyWit7I2B0UBRURzwNBWM8ODs8cSk。
)
[1] =>数组
(
[rel] => self
[type] => application / atom + xml
[href] => https://www.google.com/m8/feeds/contacts/sachitdff%40gmail.com/full/ 1?v = 3.0
)
[2] => Array
(
[rel] => edit
[type] => application / atom + xml
[href] => https://www.google。 com / m8 / feeds / contacts / sachidtfd%40gmail.com / full / 1?v = 3.0
)
)
[gd $ name] => ;数组
(
[gd $ fullName] =>数组
(
[$ t] => abc xyz
)
[gd $ givenName] =>数组
(
[$ t] => abc
)
[gd $ familyName] =>数组
(
[$ t] => xyz
)
)
[gd $ email] =>数组
(
[0] =>数组
(
[address] => abi9@gmail.com
[primary] => true
[rel] => http://schemas.google.com/g/2005#other
)
)
[gContact $ website] =>数组
(
[0] =>数组
(
[href] => http://www.google.com/profiles/104048264070958665151
[ rel] =>简档
)
)
[gContact $ groupMembershipInfo] =>数组
(
[0] =>数组
(
[deleted] => false
[href] => http://www.google .com / m8 / feeds / groups / sachitaware
)
)
但这里我没有收到用户的联系人图片。文档说我需要一个联系人ID 才能获取照片,但是我没有在上述响应中获得联系人ID。如何获取联系人用户名和随后他的联系人照片?
我已经使用oauth 2.0授权应用程序,除了图片外,我还获得了联系人的大部分详细信息。
编辑:我试过这种从文档中获得的方式,它可以工作,但它会返回二进制图像而不是图片网址,我必须发送另一个请求才能获取图片。
$ url1 ='https:// www.google.com/m8/feeds/photos/media/{useremail}/13444? V = 3.0&安培;组oauth_token = $的accessToken。
$ xmlresponse1 = curl($ url1);
显示图片:
<$ p $ < img src =data:image / *; base64,<?php echo base64_encode($ xmlresponse1);?> />
无法获取像facebook一样的联系人图片网址吗?
contactIid
: http://www.google.com/m8/feeds/contacts/<userEmail>/base/<contactId>
所以,给你的例子:
http:/ /www.google.com/m8/feeds/contacts/sfdhitdf1%40gmail.com/base/1
我们有这些值:
userEmail:sfdhitdf1@gmail.com
contactId:1
code>
I am trying to fetch user contacts with all user details uaing the google API 3.0. I am able to get the JSON response with the details of the user.
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$accesstoken;
The result is
[entry] => Array
(
[0] => Array
(
[id] => Array
(
[$t] => http://www.google.com/m8/feeds/contacts/sfdhitdf1%40gmail.com/base/1
)
[gd$etag] => "RXc7fTVSLit7I2A9XRZaEkoLRAw."
[updated] => Array
(
[$t] => 2014-08-29T00:16:24.905Z
)
[app$edited] => Array
(
[xmlns$app] => http://www.w3.org/2007/app
[$t] => 2014-08-29T00:16:24.905Z
)
[category] => Array
(
[0] => Array
(
[scheme] => http://schemas.google.com/g/2005#kind
[term] => http://schemas.google.com/contact/2008#contact
)
)
[title] => Array
(
[$t] => abc
)
[link] => Array
(
[0] => Array
(
[rel] => http://schemas.google.com/contacts/2008/rel#photo
[type] => image
[href] => https://www.google.com/m8/feeds/photos/media/sachdfwdfd%40gmail.com/1?v=3.0
[gd$etag] => "VWVIH3oyWit7I2B0UBRURzwNBWM8ODs8cSk."
)
[1] => Array
(
[rel] => self
[type] => application/atom+xml
[href] => https://www.google.com/m8/feeds/contacts/sachitdff%40gmail.com/full/1?v=3.0
)
[2] => Array
(
[rel] => edit
[type] => application/atom+xml
[href] => https://www.google.com/m8/feeds/contacts/sachidtfd%40gmail.com/full/1?v=3.0
)
)
[gd$name] => Array
(
[gd$fullName] => Array
(
[$t] => abc xyz
)
[gd$givenName] => Array
(
[$t] => abc
)
[gd$familyName] => Array
(
[$t] => xyz
)
)
[gd$email] => Array
(
[0] => Array
(
[address] => abi9@gmail.com
[primary] => true
[rel] => http://schemas.google.com/g/2005#other
)
)
[gContact$website] => Array
(
[0] => Array
(
[href] => http://www.google.com/profiles/104048264070958665151
[rel] => profile
)
)
[gContact$groupMembershipInfo] => Array
(
[0] => Array
(
[deleted] => false
[href] => http://www.google.com/m8/feeds/groups/sachitaware
)
)
But here I dont get the contact image of the user.The documentation says I need a contact id for getting the photo,but I dont get a contact id in the response above.How can I get the contact id of the user and subsequently his contact photo?
I have authorized the app using oauth 2.0 and apart from image I get most of the details of the contact.
EDIT: I tried this way from the documentation and it works,but it returns the binary image instead of the image URL and I have to send another request to get the image.
$url1 ='https://www.google.com/m8/feeds/photos/media/{useremail}/13444? v=3.0&oauth_token='.$accesstoken;
$xmlresponse1 = curl($url1);
To display the image:
<img src="data:image/*;base64,<?php echo base64_encode($xmlresponse1); ?> />
Can't I get the contact image URL something like facebook returns?
According the documentation, contactIid
is returned in the contact entry URL returned by the API:
http://www.google.com/m8/feeds/contacts/<userEmail>/base/<contactId>
So, giving your sample:
http://www.google.com/m8/feeds/contacts/sfdhitdf1%40gmail.com/base/1
We have these values:
userEmail: sfdhitdf1@gmail.com
contactId: 1
这篇关于如何使用PHP使用Google API获取用户'contactid'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!