1

我用这个代码,直到昨天:谷歌分析API认证

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

require 'gapi.php'; 

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

如今,它开始给我的错误:

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

错误: “https://developers.google.com/accounts/docs/AuthForInstalledApps” 在C:\ WAMP \ WWW \项目\ gapi.php上线418

是否有任何变化最近关于认证过程?

+0

此问题是由于身份验证方法(ClientLogin to OAuth)的更改所致。按照https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php?hl=pt-br中的说明解决了我的问题。希望能帮助到你。 –

回答

0

请参见:GAPI: Failed to authenticate user. Permanent fix PHP

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或使用Google API PHP客户端https://github.com/google/google-api-php-client)。

+0

感谢您的回复,我使用github提供的gapi.php和上面提到的认证StigM,它解决了我的问题。 –

0

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

请注意,OAuth2将要求您登录create a 'service account',然后下载P12文件以上传到服务器。最后,您需要调整开发者控制台,启用“分析API”。最后,为您希望访问的Google Analytics帐户授予此新用户的“读取和分析”权限。