0

私は連絡先リストを取得するためにグーグルの最新のAPIを使用しています。このコードは、私のリストの最初の20項目をXMLで出力しているようです。
質問:リスト全体を出力するにはどうすればよいですか?

<?php
require_once '../../src/apiClient.php';
session_start();

$client = new apiClient();
$client->setApplicationName('Google Contacts PHP Sample');
$client->setScopes("http://www.google.com/m8/feeds/");
// Documentation: http://code.google.com/apis/gdata/docs/2.0/basics.html
// Visit https://code.google.com/apis/console?api=contacts to generate your
// oauth2_client_id, oauth2_client_secret, and register your oauth2_redirect_uri.
// $client->setClientId('insert_your_oauth2_client_id');
// $client->setClientSecret('insert_your_oauth2_client_secret');
// $client->setRedirectUri('insert_your_redirect_uri');
// $client->setDeveloperKey('insert_your_developer_key');

if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}

if (isset($_SESSION['token'])) {
 $client->setAccessToken($_SESSION['token']);
}

if (isset($_REQUEST['logout'])) {
    unset($_SESSION['token']);
    $client->revokeToken();
}

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

    // The contacts api only returns XML responses.
    /* * * * * * * * * produced an error
    $response = json_encode(simplexml_load_string($val->getResponseBody()));
    print "<pre>" . print_r(json_decode($response, true), true) . "</pre>"; 
    */

    // fix
    $response = $val->getResponseBody();
    print "<pre>" . print_r($response) . "</pre>";


    // The access token may have been updated lazily.
    $_SESSION['token'] = $client->getAccessToken();
} else {
    $auth = $client->createAuthUrl();
}

if (isset($auth)) {
        print "<a class=login href='$auth'>Connect Me!</a>";
    } else {
        print "<a class=logout href='?logout'>Logout</a>";
}
?>

私はこの応答を見ましたが、それを実装する方法がわかりません

。まず、extendedPropertiesが返されないため、バージョン3を要求する必要があります。これがいくつかの動作中のコードからのcnpです。

function get($xmlfile) {
try {
  @$feed = simplexml_load_file($xmlfile. '&v=3.0');
  if ($feed === FALSE) {
    throw new Exception(file_get_contents($xmlfile));
  }
} catch (Exception $e) {
  return array('error' => true, 'payload' => $e->getMessage());
}
return array('error' => false, 'payload' => $xmlData);
}

次に探すべきことは、gd名前空間を使用することをsimplexmlに伝えることです。もう一つの例:

 $this->nsGd = $xmlData->children('http://schemas.google.com/g/2005');
 ...
 $this->email = @(string)$this->nsGd->email->attributes()->address;
 ...
 foreach ($this->nsGd->extendedProperty as $x) {
    if ($x->attributes()->name == 'ethnicity') {
      $this->ethnicity = $x->attributes()->value;
    }
  } 
4

1 に答える 1

2

max-resultsクエリパラメータを使用してみましたか?連絡先APIドキュメントから。

:返される結果の数にはデフォルトの制限があるため、フィードにユーザーの連絡先のすべてが含まれているとは限りません。詳細については、クエリパラメータを使用した連絡先の取得のmax-resultsクエリパラメータを参照してください。

したがって、次のようなリクエストを送信できます:https ://www.google.com/m8/feeds/contacts/default/full?max-results=1000

于 2012-07-12T21:09:34.143 に答える