我正在使用谷歌分析apis v3来接收流量数据,使用的语言是php,问题是直到前几天我获得了数据,现在我有这个错误: (401)需要登录 我登录了: gmail.com analytics.google.it 在谷歌的控制台上都正常启用,因为几天前它工作.. 这里: http://ga-dev-tools.appspot.com/explorer/ 好好工作 .. 验证码是:
require_once '/analytics/src/Google_Client.php';
require_once '/analytics/src/contrib/Google_AnalyticsService.php';
$client = new Google_Client();
$client->setAccessType('offline'); // default: offline
$client->setApplicationName('#########ca1');
$client->setClientId('#########99.apps.googleusercontent.com');
$client->setClientSecret('#########hs33t');
$client->setRedirectUri("#########/analytics/oauth2callback.php");
$client->setDeveloperKey('#########y86ePKOcHs'); // API key
# $service implements the client interface, has to be set before auth call
$service = new Google_AnalyticsService($client);
if (isset($_GET['logout'])) { // logout: destroy token
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
}
参数$ _GET ['code']
为空,然后不创建会话令牌。
也许它工作了几天只是因为在我所做的各种代码测试中都记录了。
答案 0 :(得分:0)
您应该将$_GET['code']
作为参数传递给$client->authenticate()
方法,就像那样
$client->authenticate($_GET['code']);