分析PHP界面(GAPI)用户模拟

Jam*_*mes 5 php google-analytics google-api

我目前在几个不同的Google帐户中有大约100个Google Analytics网站,一个帐户拥有每个网站的完全权限.如果可能,我希望避免将Google服务帐户的权限手动添加到每个分析配置文件.

我正在使用Google Analytics PHP界面

尝试使用$ delegate_email参数模拟用户时,出现以下异常:

GAPI: Failed to authenticate user. Error: "{
    "error": "unauthorized_client",
    "error_description": "Unauthorized client or scope in request."
}
Run Code Online (Sandbox Code Playgroud)

我在其他地方读过有关需要使用Google Apps管理控制台"域范围权限委派给服务帐户"的信息.但是,我们根本没有Google Apps.有没有办法解决?

tl; dr 是否有办法使用服务帐户获取对Google Analytics的只读访问权限并假冒没有Google Apps的用户?

Mat*_*att 2

我首先鼓励您浏览Google OAuth 2.0文档中列出的各种场景,并决定哪一个最适合您的应用程序。

服务帐户要求您向要访问的每个帐户添加一个用户,但使用Web 服务器应用程序时,最终用户只需授权您的应用程序读取其 Google 分析数据即可。

您正在寻找的范围是:

https://www.googleapis.com/auth/analytics.readonly
Run Code Online (Sandbox Code Playgroud)