&引用;致命错误:类';谷歌Http请求&x27;在“中找不到”;使用Oauth2.0身份验证和Google Contact API for PHP时

&引用;致命错误:类';谷歌Http请求&x27;在“中找不到”;使用Oauth2.0身份验证和Google Contact API for PHP时,php,api,oauth,Php,Api,Oauth,我正在尝试使用谷歌联系人API检索我的所有联系人。为此,我使用了Oauth2.0身份验证和Google Contact API For PHP 但我得到了这个错误: “致命错误:在中找不到类‘Google_Http_请求’” 找不到原因。我甚至使用了Google_HttpRequest,但错误仍然是一样的,但这次是针对“Google_HttpRequest” 使用的代码如下所示,有人能帮上忙吗?因为在互联网上没有帮助 <?php //require_once 'C:/xampp/htdoc

我正在尝试使用谷歌联系人API检索我的所有联系人。为此,我使用了Oauth2.0身份验证和Google Contact API For PHP

但我得到了这个错误: “致命错误:在中找不到类‘Google_Http_请求’”

找不到原因。我甚至使用了Google_HttpRequest,但错误仍然是一样的,但这次是针对“Google_HttpRequest”

使用的代码如下所示,有人能帮上忙吗?因为在互联网上没有帮助

<?php
//require_once 'C:/xampp/htdocs/google-api-php-client-master/src/Google/Client.php';

require_once 'C:/xampp/htdocs/google-api-php-client-master/vendor/autoload.php';// or wherever autoload.php is located
session_start();
//Declare your Google Client ID, Google Client secret and Google redirect uri in  php variables
$google_client_id = 'xxx-yyy.apps.googleusercontent.com';
$google_client_secret = 'xxxx';
$google_redirect_uri = 'https://localhost:4433/xxx.php';
$client = new Google_Client();
$client -> setApplicationName('My application name');
$client -> setClientid($google_client_id);
$client -> setClientSecret($google_client_secret);
$client -> setRedirectUri($google_redirect_uri);
$client -> setAccessType('online');

$client->setApplicationName('Google Contacts PHP Sample');

$client->setScopes("http://www.google.com/m8/feeds/");

///if (isset($_GET['code'])) {

/// $client->authenticate($_GET['code']);

/// $auth_code = $_GET["code"];

/// $_SESSION['google_code'] = $auth_code;

/// header('Location: ' . $google_redirect_uri);

///}

if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_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 Google_Http_Request("https://www.google.com/m8/feeds/contacts/default/full", 'GET', null, null);   
$req = new Google_Http_Request("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>";
}

您试图混合无法混合的东西

您正在使用的当前版本仅支持发现服务API。哪些是返回Json的新API


GoogleContactsAPI是一个旧的GDataAPI,它返回XML。这两个人说的语言不同。我没有尝试过,但是可以在这里找到旧的客户端库。

您正在尝试混合无法混合的内容

您正在使用的当前版本仅支持发现服务API。哪些是返回Json的新API


GoogleContactsAPI是一个旧的GDataAPI,它返回XML。这两个人说的语言不同。我没有尝试过,但是可以在这里找到旧的客户端库。

@DalmTo我的目标是使用Google Contact API和Oauth2.0检索GMAIL中的所有联系人。您能建议使用哪种API吗?您只能使用一种API。但是您使用了错误的客户端库。您需要使用Gdata客户端库。@Dalm我可以从哪里下载这个库?@Dalm不能使用新API在GMAIL和Oauth2.0中检索联系人。Google contacts API没有新API,v3是Google contacts的当前API。是的,可以使用Oauth2访问它。据我所知,这是使用Oauth2进行身份验证的唯一方法。在我的回答@DalmTo中,我给了你Gdata客户端库的链接。我的目标是使用Google Contact API和Oauth2.0检索GMAIL中的所有联系人。你能建议使用哪种API吗?你只能使用一种API。但是您使用了错误的客户端库。您需要使用Gdata客户端库。@Dalm我可以从哪里下载这个库?@Dalm不能使用新API在GMAIL和Oauth2.0中检索联系人。Google contacts API没有新API,v3是Google contacts的当前API。是的,可以使用Oauth2访问它。据我所知,这是使用Oauth2进行身份验证的唯一方法。我在回答中给了你Gdata客户端库的链接