【发布时间】:2015-07-14 12:03:15
【问题描述】:
我使用的是Google Contacts 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 中获取个人资料图片,但我不确定如何在我生成的 DOMXPath $xpath 对象中找到它。
想法?
【问题讨论】:
标签: php xml google-api google-api-php-client google-contacts-api