【发布时间】:2016-07-26 06:43:24
【问题描述】:
我正在使用 Google Contacts 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);
}
}
如何获取联系地址。他们(google api)提到了 formattedAddress ,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 放在一个变量中
【问题讨论】:
标签: php google-api google-contacts-api