PHP谷歌API客户端v3获取联系人

PHP谷歌API客户端v3获取联系人,php,xml-parsing,google-api,google-api-php-client,Php,Xml Parsing,Google Api,Google Api Php Client,我仍然有新的谷歌api客户端php库的问题。我正在尝试检索用户的联系人 我非常接近正确的解决方案。。。我的意思是,我刚刚得到了所有的结果,但a无法解析它 可能是因为我不擅长XML解析器。经过一次又一次的测试。。。我根据Google提供的示例文件得到了这个解决方案: ... $req = new apiHttpRequest("https://www.google.com/m8/feeds/contacts/default/full"); $val = $client->g

我仍然有新的谷歌api客户端php库的问题。我正在尝试检索用户的联系人

我非常接近正确的解决方案。。。我的意思是,我刚刚得到了所有的结果,但a无法解析它

可能是因为我不擅长XML解析器。经过一次又一次的测试。。。我根据Google提供的示例文件得到了这个解决方案:

...
$req = new apiHttpRequest("https://www.google.com/m8/feeds/contacts/default/full");         
$val = $client->getIo()->authenticatedRequest($req);
$response = simplexml_load_string($val->getResponseBody());

foreach($response->entry as $entry)
{
    $child = $entry->children("http://schemas.google.com/g/2005");
    $mail_info = $child->attributes();
}
...
在$response中,我可以获得存储联系人全名的title字段,在$mail_info中,我可以获得一个对象,当我获得电子邮件地址时,我可以在其中看到address字段

这是一个悲哀而丑陋的解决方案。。。如果我想要公司的名称,地址。。。电话号码。。。照片。这些信息都在哪里

我如何在一个好的、干净的解决方案中使用Google响应

任何人都可以给我一些帮助。
再见,帮助我的是请求JSON而不是XML。尝试将?alt=json添加到您向google发出的请求的URL末尾

$req = new apiHttpRequest("https://www.google.com/m8/feeds/contacts/default/full?alt=json");         
$val = $client->getIo()->authenticatedRequest($req);
$string = $val->getResponseBody();
$phparray = json_decode($string);
当然,要得到您想要的东西并非儿戏,但使用php数组可能更容易

就完整性而言,这可能是我们双方都发现的帮助我们的原因:

编辑:

下面是另一个可能有用的链接。在注释中,它描述了一种使用JSON访问联系人数据的方法


帮助我的是请求JSON而不是XML。尝试将?alt=json添加到您向google发出的请求的URL末尾

$req = new apiHttpRequest("https://www.google.com/m8/feeds/contacts/default/full?alt=json");         
$val = $client->getIo()->authenticatedRequest($req);
$string = $val->getResponseBody();
$phparray = json_decode($string);
当然,要得到您想要的东西并非儿戏,但使用php数组可能更容易

就完整性而言,这可能是我们双方都发现的帮助我们的原因:

编辑:

下面是另一个可能有用的链接。在注释中,它描述了一种使用JSON访问联系人数据的方法


如果您使用file\u get\u内容而不是curl\u file\u get\u内容,效果非常好如果您使用file\u get\u内容而不是curl\u file\u get\u内容,效果非常好
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$accesstoken;
$xmlresponse =  curl_file_get_contents($url);

$temp = json_decode($xmlresponse,true);

foreach($temp['feed']['entry'] as $cnt) {
    echo $cnt['title']['$t'] . " --- " . $cnt['gd$email']['0']['address'];
    if(isset($cnt['gd$phoneNumber'])) echo " --- " . $cnt['gd$phoneNumber'][0]['$t'];
    if(isset($cnt['gd$structuredPostalAddress'][0]['gd$street'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$street']['$t'];
    if(isset($cnt['gd$structuredPostalAddress'][0]['gd$neighborhood'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$neighborhood']['$t'];
    if(isset($cnt['gd$structuredPostalAddress'][0]['gd$pobox'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$pobox']['$t'];
    if(isset($cnt['gd$structuredPostalAddress'][0]['gd$postcode'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$postcode']['$t'];
    if(isset($cnt['gd$structuredPostalAddress'][0]['gd$city'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$city']['$t'];
    if(isset($cnt['gd$structuredPostalAddress'][0]['gd$region'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$region']['$t'];
    if(isset($cnt['gd$structuredPostalAddress'][0]['gd$country'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$country']['$t'];
    echo "</br>";
}