【发布时间】:2015-01-14 23:40:40
【问题描述】:
我最近下载了用于 PHP 的 Google API 客户端库,将其上传到我的网站,并使用 Google 提供的代码连接我的日历。第一部分效果很好。我被发送到:https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http 我按下接受按钮。我使用 authcode 被重定向回这个文件。但是这条线失败了:
$accessToken = $client->authenticate($authCode);
require_once ('google-api-php-client/autoload.php'); // path to autoload.php
if ($_GET[code] == FALSE) {
$client = new Google_Client();
$client->setClientId('My client ID');
$client->setClientSecret('My secret');
$client->setRedirectUri('http://'); // path to this file.
$client->addScope('https://www.googleapis.com/auth/calendar');
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$service = new Google_Service_Calendar($client);
$authUrl = $client->createAuthUrl();
header("location: $authUrl"); // sends me to account.google.com I accept and get send back to this file :-)
}
Else {
//$authCode = trim(fgets(STDIN));
$authCode = $_GET[code]; // get authcode from google
//Exchange authorization code for access token
$accessToken = $client->authenticate($authCode); //Fatal error: Call to a member function on a strong text**non-object in authenticate() on line 23
$client->setAccessToken($accessToken);
【问题讨论】:
-
它是如何失败的?它会给出错误消息吗?我们需要更多信息来帮助您。
-
应该是$_GET['code']
标签: php api authentication