如何使用PHP获取用户的'contactid'使用谷歌API
问题描述:
我想通过谷歌API 3.0获取所有用户详细信息的用户联系人。 我能够得到与用户的细节JSON响应。如何使用PHP获取用户的'contactid'使用谷歌API
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$accesstoken;
结果是
[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] => [email protected]
[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
)
)
但在这里我不明白的接触式图像的user.The documentation说我需要一个接触式ID用于获取照片,但我不明白上述回复中的联系人ID。如何获取用户的联系人ID以及他的联系人照片?
我已经授权使用oauth 2.0的应用程序,除了图像以外,我获得了大部分联系人的详细信息。
编辑:我试图this方式从文档和它的作品,但它返回的二进制图像,而不是图像URL,我必须再次提出请求,以获得图像。
$url1 ='https://www.google.com/m8/feeds/photos/media/{useremail}/13444? v=3.0&oauth_token='.$accesstoken;
$xmlresponse1 = curl($url1);
要显示的图像:
<img src="data:image/*;base64,<?php echo base64_encode($xmlresponse1); ?> />
我还是不能接触式图像URL类似Facebook的回报?
答
根据该文件,contactIid
在通过API返回的联系人条目URL返回:
http://www.google.com/m8/feeds/contacts/<userEmail>/base/<contactId>
所以,给你的样品:
http://www.google.com/m8/feeds/contacts/sfdhitdf1%40gmail.com/base/1
我们有这些值:
userEmail: [email protected]
contactId: 1
在userEmail中,我在输出中的每一处都有我的电子邮件ID,并且基值始终在变化数字转换为字母。例如:'http:// www.google.com/m8/feeds/contacts/sachitaware21%40gmail.com/base/f'和'http://www.google.com/m8/feeds/触点/ sachitaware21%40gmail.com /碱/ 13'。我有这两个作为联系人的URL,所以f和13分别是联系人ID吗? – KillABug 2014-10-18 06:40:01
是不是将联系人图像的URL与联系人列表API一起返回?否则,每次我想要获取联系人图像时,都必须发送针对每个联系人的单独请求。如果列表很大,这将需要很长时间。 – KillABug 2014-10-18 07:44:42