我正在使用Google联系人API,我可以提取姓名和电子邮件地址、电话号码、图像,但我也想获得联系地址、注释以及如何提取电子邮件作为工作或家庭
我使用的是PHP,以下是我在验证时的代码:
$document = new DOMDocument();
$document->loadXml($xmlresponse);
$xpath = new DOMXpath($document);
$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
$xpath->registerNamespace('gd', 'http://schemas.google.com/g/2005');
foreach ($xpath->evaluate('/atom:feed/atom:entry') as $entry) {
$contact = [
'name' => $xpath->evaluate('string(atom:title)', $entry),
'image' => $xpath->evaluate('string(atom:link[@rel="http://schemas.google.com/contacts/2008/rel#photo"]/@href)', $entry),
'emails' => [],
'numbers' => [],
'conatctaddress' => []
];
foreach ($xpath->evaluate('gd:email', $entry) as $email) {
$contact['emails'][] = $email->getAttribute('address');
}
foreach ($xpath->evaluate('gd:phoneNumber', $entry) as $number) {
$contact['numbers'][] = trim($number->textContent);
}
}
如何获取联系人地址。他们(谷歌api)提到了formatedAddress、structuredPostalAddress,但没有提到如何获取,也没有提到它是家里的还是工作的
编辑
正如下面的答案中所提到的,我正在获得xml响应,但该响应并不完整。因为联系方式还包含出生日期、周年纪念日和网站详细信息,所以这些详细信息无法通过获取
https://www.google.com/m8/feeds/contacts/default/full?&oauth_token=abcdferyyrfyfyt
以及我正在获得的剩余数据作为
<gd:organization rel='http://schemas.google.com/g/2005#other'><gd:orgName>comright</gd:orgName><gd:orgTitle>software developer</gd:orgTitle></gd:organization>
因此,当我尝试foreach loop
时,我在一个变量中获得orgName
和orgTitle
您可以使用GET方法到url端点"https://www.google.com/m8/feeds/contacts/{userEmail}/full"从谷歌中检索联系人。您也可以通过链接。它会对您有所帮助。