我正在使用Google联系人API,我能够提取姓名和电子邮件地址,但我也想获取个人资料图片和电话号码。
我正在使用PHP,这是我的认证代码:
//if authenticated successfully...
$req = new Google_HttpRequest("https://www.google.com/m8/feeds/contacts/default/full");
$val = $client->getIo()->authenticatedRequest($req);
$doc = new DOMDocument;
$doc->recover = true;
$doc->loadXML($val->getResponseBody());
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('gd', 'http://schemas.google.com/g/2005');
$emails = $xpath->query('//gd:email');
foreach ( $emails as $email ){
echo $email->getAttribute('address'); //successfully gets person's email address
echo $email->parentNode->getElementsByTagName('title')->item(0)->textContent; //successfully gets person's name
}
电话号码
获取电话号码的这部分无法正常工作。
$phone = $xpath->query('//gd:phoneNumber');
foreach ( $phone as $row ){
print_r($row); // THIS PART DOESNT WORK
}
个人头像
从上面的API链接来看,我似乎也可以从URL中获取个人头像:https://www.google.com/m8/feeds/contacts/default/full
但是我不确定如何在我生成的$xpath
对象中找到它。
有什么想法吗?
'image' => $xpath->evaluate('string(atom:link[@rel="http://schemas.google.com/contacts/2008/rel#photo"]/@href)', $entry). '&access_token='.urlencode($accesstoken)
,图像仍然给我带来问题。您能帮忙吗? - tim petersonGoogle_HttpRequest
对象发送授权的GET请求到图像URL以获取它。就像获取XML feed一样,但将响应存储/传递为二进制图像数据。我的示例是否从XML feed中读取有效的图像URL? - ThW