Google maps api 3 Google analytics API v3错误401需要登录

Google maps api 3 Google analytics API v3错误401需要登录,google-maps-api-3,login,analytics,required,Google Maps Api 3,Login,Analytics,Required,我正在使用google analytics API v3来接收流量数据,使用的语言是php,问题是直到几天前我才获得数据,现在我出现了以下错误: 401需要登录 我登录: gmail.com analytics.google.it 在谷歌的控制台上,所有的功能都被正确地启用了,因为几天前它还可以工作。。 在这里: 工作正常。。 身份验证代码如下所示: require_once '/analytics/src/Google_Client.php'; require_once '/analytics

我正在使用google analytics API v3来接收流量数据,使用的语言是php,问题是直到几天前我才获得数据,现在我出现了以下错误: 401需要登录 我登录: gmail.com analytics.google.it 在谷歌的控制台上,所有的功能都被正确地启用了,因为几天前它还可以工作。。 在这里: 工作正常。。 身份验证代码如下所示:

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();
}
参数$\u GET['code']为空,则不会创建会话令牌。 可能它工作了几天,只是因为在我所做的各种代码测试中都记录了日志。

您应该将$\u GET['code']作为参数传递给$client->authenticate方法,就像这样

$client->authenticate$_GET['code'];