Php 导入google联系人时的OAuth问题

Php 导入google联系人时的OAuth问题,php,authentication,oauth-2.0,google-plus,google-oauth,Php,Authentication,Oauth 2.0,Google Plus,Google Oauth,早上好-我正在使用下面的YouTube教程尝试导入Google联系人 当我点击链接导入Google联系人时,我没有请求权限并获取联系人并将其显示在屏幕上,而是出现以下错误: 警告:调用的Google_Client::authenticate()缺少参数1 在第34行的/var/www/html/restaurant_test/index.php中,并在中定义 /var/www/html/restaurant\u test/lib/google-api-client/google\u-client

早上好-我正在使用下面的YouTube教程尝试导入Google联系人

当我点击链接导入Google联系人时,我没有请求权限并获取联系人并将其显示在屏幕上,而是出现以下错误:

警告:调用的Google_Client::authenticate()缺少参数1 在第34行的/var/www/html/restaurant_test/index.php中,并在中定义 /var/www/html/restaurant\u test/lib/google-api-client/google\u-client.php 在线124

注意:未定义变量:中的代码 /var/www/html/restaurant\u test/lib/google-api-client/google\u-client.php 在线127

致命错误:未捕获异常“Google\u Auth\u exception”并显示消息 中的“无效代码” /var/www/html/restaurant\u test/lib/google-api-client/Auth/OAuth2.php:88 堆栈跟踪:#0 /var/www/html/restaurant\u test/lib/google-api-client/google\u-client.php(127): Google_Auth_OAuth2->身份验证(NULL,false)#1 /var/www/html/restaurant_test/index.php(34): Google_Client->authenticate()#2{main}被抛出 /var/www/html/restaurant_test/lib/google api client/Auth/OAuth2.php on 第88行

请告诉我如何修复错误。多谢各位

这是我的密码:

<?php 
error_reporting(E_ALL);
ini_set("display_errors", 1);

session_start(); ?>
<!DOCTYPE html>
<html class="no-js" lang="en"/>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Google Contacts API</title>
</head>

<body>
<h2>Google Contacts API v3.0</h2>
<?php
require_once 'lib/google-api-client/autoload.php';
require 'lib/google-api-client/Config.php';
require 'lib/google-api-client/Google_Client.php';

$client_id = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbb.cccccccccccc.com';
$client_secret = 'oUe3fsfds4gfg23ha93kmKFkfgKZ';
$redirect_uri = 'http://ccccccccccccccccccc.com/rddddddddddd/index.php';

$client = new Google_Client();
$client -> setApplicationName('contact');
$client -> setClientid($client_id);
$client -> setClientSecret($client_secret);
$client -> setScopes('https://www.google.com/m8/feeds');
$client -> setRedirectUri($redirect_uri);
$client -> setAccessType('online');

if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: ' . $redirect_uri);
}

if(!isset($_SESSION['token']))
{
    $url = $client->createAuthUrl();
    echo '<a href="' . $url . '">Import Google Contacts</a>';
}else{
        $client->setAccessToken($_SESSION['token']);
        $token = json_decode($_SESSION['token']);
        $token->access_token;
        $curl = curl_init("https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=50&access_token=" . $token->access_token);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        $contacts_json = curl_exec($curl);
        curl_close($curl);
        $contacts = json_decode($contacts_json, true);
        $return = array();
        foreach($contacts['feed']['entry'] as $contact){
            $return[] = array(
            'name' => $contact['title']['$t'],
            'email' => isset($contact['gd$email'][0]['address']) ? $contact['gd$email'][0]['address'] : false,
            'phone' => isset($contact['gd$phoneNumber'][0]['$t']) ? $contact['gd$phoneNumber'][0]['$t'] :false,
            );
        }
        var_dump($return);
    }       
?>

</body>
</html>

谷歌联系人API
谷歌联系人API v3.0

看起来您忘记将
code
传递给
authenticate
方法。以下是中的
验证
方法的文档和实现:

因此,按以下方式更改代码很可能会解决此问题:

if (isset($_GET['code'])) {
    $client->authenticate($_GET['code']); // <-- Add code parameter here
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: ' . $redirect_uri);
}
if(isset($\u GET['code'])){
$client->authenticate($_GET['code']);//getAccessToken();
标题('Location:'。$redirect_uri);
}

看起来您忘记将
code
传递给
authenticate
方法。以下是中的
验证
方法的文档和实现:

因此,按以下方式更改代码很可能会解决此问题:

if (isset($_GET['code'])) {
    $client->authenticate($_GET['code']); // <-- Add code parameter here
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: ' . $redirect_uri);
}
if(isset($\u GET['code'])){
$client->authenticate($_GET['code']);//getAccessToken();
标题('Location:'。$redirect_uri);
}
lib/google api client/Auth public function authenticate($code,$crossClient=false){$This->authenticate=true;return$This->getAuth()->authenticate($code,$crossClient);}这是函数“authenticate”在OAuth2.php中的lib/google api client/Auth公共函数authenticate($code,$crossClient=false){$this->authenticate=true;return$this->getAuth()->authenticate($code,$crossClient);}-ur right-它解决了这些错误,非常感谢-但是,我的显示器很难看,只能显示50而不是全部-你的权利-它解决了这些错误非常感谢-然而,我的显示器很难看,只能显示50而不是全部