1

新しい google_api_client php ライブラリにはまだ問題があります。ユーザーの連絡先を取得しようとしています。

私は正しい解決策に非常に近づいています...つまり、すべての結果を取得したばかりですが、それを解析できません。

それはおそらく、私が 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 では、連絡先の氏名が格納されているタイトル フィールドを取得できます。また、$mail_info では、メール アドレスを取得したときにアドレス フィールドが表示されるオブジェクトを取得できます。

それは悲しくて醜い解決策です...会社名、住所...電話番号...写真が必要な場合はどうすればよいですか。これらすべての情報はどこにありますか。

優れたクリーンなソリューションで Google の応答を使用するにはどうすればよいですか?

誰でも私に助けを与えることができます。さよなら

4

1 に答える 1

6

XML の代わりに JSON を要求することが役に立ちました。?alt=jsonGoogle へのリクエストの 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配列を操作する方がおそらく簡単です。

完全を期すために、これはGoogle の連絡先の php の例です。

https://code.google.com/p/google-api-php-client/source/browse/trunk/examples/contacts/simple.php

編集:

これが役立つかもしれない別のリンクです。コメントでは、JSON を使用して連絡先のデータにアクセスするためのクリーナーについて説明しています。

http://25labs.com/import-gmail-or-google-contacts-using-google-contacts-data-api-3-0-and-oauth-2-0-in-php/

$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'] . "</br>";
}

$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>";
}
于 2013-11-07T22:25:52.690 に答える