Google 分析 API 身份验证

Google Analytics API authentication

直到昨天我都在使用这段代码:

$gaemail = 'my email';
$gapassword = 'my password';
$gaprofileid = 'my profile id';

require 'gapi.php';

$ga = new gapi($gaemail,$gapassword);

今天开始报错:

异常:GAPI:无法验证用户。

错误:C:\wamp\www\projects\gapi.php 中的“https://developers.google.com/accounts/docs/AuthForInstalledApps”第 418 行

最近关于身份验证过程有什么变化吗?

参见:

GAPI hasn't been worked on since 2009. It also appears to use client login which was discontinued / shutdown on April 20 2015. You can no longer use client login with Google Analytics API, you need to switch to Oauth2 or a service account. So either the author of that project needs to fix his code, it appears to be an open source project so you could probably fix it for him.

你有几个选择。看起来 最新版本的 GAPI 现在支持 oauth - 请参阅:https://github.com/erebusnz/gapi-google-analytics-php-interface or use the Google API PHP Client (https://github.com/google/google-api-php-client)。

Version 2.0 on GitHub的GAPI已经发布,支持OAuth2认证。 Google 已禁用所有其他形式的身份验证。

请注意,OAuth2 将要求您 create a 'service account' 然后下载一个 P12 文件以上传到服务器。最后你需要调整开发者控制台,启用'analytics API'。最后授予此新用户 'Read and Analyse' 您要访问的 Google Analytics 帐户的权限。