谷歌+;PHP中的oAuth联系人完整列表
我正在使用谷歌最新的api检索联系人列表。这段代码似乎以XML格式输出了我列表的前20项。谷歌+;PHP中的oAuth联系人完整列表,php,oauth,google-plus,Php,Oauth,Google Plus,我正在使用谷歌最新的api检索联系人列表。这段代码似乎以XML格式输出了我列表的前20项。 问题:如何输出整个列表? <?php require_once '../../src/apiClient.php'; session_start(); $client = new apiClient(); $client->setApplicationName('Google Contacts PHP Sample'); $client->setScopes("http://www.g
问题:如何输出整个列表?
<?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>";
}
?>
接下来要寻找的是告诉simplexml您想要的东西
使用gd名称空间。另一个例子:
您是否尝试过使用max results查询参数?从 注意:提要可能不包含用户的所有联系人,因为返回的结果数量有默认限制。更多 有关详细信息,请参见中的“最大结果”查询参数
因此,您可以发送一个请求,例如:我觉得答案有冲突,因为它说
要检索用户的所有联系人,请向以下URL发送一个授权GET请求:
,然后它说可能有限制该请求默认最大结果为25。如果添加max_results参数,则可以覆盖它。我用我的一个谷歌账户试过,一次检索了282个联系人。
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);
}
$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;
}
}