Google API:循环多个帐户时出现错误错误

时间:2018-07-27 15:50:13

标签: google-api google-analytics-api google-api-php-client

我刚刚更新到google-api-php-client的最新版本。找不到我正在运行的以前的版本号,但它是从code.google.com上返回的。肯定是几岁了。

在特定情况下出现此错误。

{"error":{"errors":[{"domain":"global","reason":"insufficientPermissions","message":"User does not have sufficient permissions for this profile."}],"code":403,"message":"User does not have sufficient permissions for this profile."}}

此代码过去可以在旧版本上正常工作。我正在做的是通过几个Google Analytics(分析)帐户循环读取一些数据。我在循环之前有以下代码。

$client = new Google_Client();
$client->setApplicationName("name");
$client->setClientId('123.apps.googleusercontent.com');
$client->setClientSecret('secret');
$service = new Google_Service_Analytics($client);

然后在循环内,对每个帐户,我执行$client->refreshToken($token)$token是保存在数据库中的刷新令牌。如果我仅通过一个帐户,它就可以正常工作。问题似乎是因为我重用了相同的Google_Client对象。如果我在循环中重新定义Google_Client,它将按预期工作。但这感觉很脏,尤其是当名称,ID和机密都相同时。我应该注意,当我运行$client->refreshToken($token)时,访问令牌已正确设置,并由$client->getAccessToken()确认。

是否有适当的方法来重置Google_Client对象,以便不重新定义它?

1 个答案:

答案 0 :(得分:0)

  

用户对此个人资料没有足够的权限

仅仅意味着您与脚本进行身份验证的用户无权访问您尝试访问的配置文件。

您尚未包含用于访问Google Analytics(分析)的任何代码,但应在某些位置添加诸如视图ID或个人资料ID之类的内容。您需要使用具有访问权限的用户登录。