我验证了一个简单的获取 使用服务帐户请求Core Reporting API。但反应总是:
{"error":{"errors": [{"message":"Forbidden"}],"code":403,"message":"Forbidden"}}
当我通过“Web客户端ID”验证相同的api请求时 应用程序“(OAuth 2.0 Playground)我得到api响应没有问题。所以问题不在api查询中。
这就是我所做的:
我使用了一个帐户在google api控制台登录 访问分析帐户
我在有权访问的项目中创建了一个新的服务帐户 分析api
使用最新的google-api-php-client我验证了请求
使用此服务帐户访问分析API。身份验证
似乎工作正常,因为请求标头包含authorization:
Bearer {access_token}
。但我总是得到403。
以下是我正在做的简短代码片段:
$client = new apiClient();
$client->setAssertionCredentials(new apiAssertionCredentials(
'{my_service_account_email}',
array('https://www.googleapis.com/auth/analytics.readonly'),
'{my_service_account_certificate}'
));
$request = $client->getIo()->authenticatedRequest(new apiHttpRequest('https://www.googleapis.com/analytics/v3/data/ga?{my_query}'));
我做错了什么?
答案 0 :(得分:0)
我在谷歌小组得到了答案:
不幸的是,所有Google API都不支持服务帐户。我们正在努力更广泛地实现它。
https://groups.google.com/group/oauth2-dev/browse_thread/thread/3414283abb5c0ba0
答案 1 :(得分:0)
对于那些仍在寻求答案的人来说,这可能是有用的
您需要将client_id与您的Google Analytics帐户相关联,可在http://www.pimcore.org/wiki/display/PIMCORE/Setup+Google+Analytics+Reporting+with+OAuth2+Service+Accounts+(since+1.4.6找到一些插图说明