谷歌联系 API 无法设置它



我就是无法让它工作。我使用的是谷歌 php 库中示例中的简单.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');
$client->setClientId('xxxxxxxxxxx.apps.googleusercontent.com');
$client->setClientSecret('xxxxxxxxxxxxxx');
$client->setRedirectUri('https://www.xxxxxxxxxxxxxxx.com/oauth2callback');
$client->setDeveloperKey('xxxxxxxxxxxxxxxxx');
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.
  $response = json_encode(simplexml_load_string($val->getResponseBody()));
  print "<pre>" . print_r(json_decode($response, true), true) . "</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>";
}

在页面中,我收到注销消息,并且从获取中收到错误。 我在 Apache 错误日志中看到:

PHP Warning:  simplexml_load_string(): <ins>That&#39;s all we know.</ins></p></body></html> in /www/xxxxxxxxxxxxxxx.com/docs/oauth2callback/google-api-php-client/examples/contacts/index.php on line 58

我正在尝试几个小时来得到它。 第一次尝试JavaScript,不能。 现在尝试PHP。

更新:最后,我找到了这个完美运行的链接:http://25labs.com/import-gmail-or-google-contacts-using-google-contacts-data-api-3-0-and-oauth-2-0-in-php/

更改

$response = json_encode(simplexml_load_string($val->getResponseBody()));
print "<pre>" . print_r(json_decode($response, true), true) . "</pre>";

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

这将打印出联系人的第一页,但我似乎无法获得更多页面

相关内容

  • 没有找到相关文章

最新更新