【问题标题】:google analytics "Request had insufficient authentication scopes"; "status": "PERMISSION_DENIED" Error谷歌分析“请求的身份验证范围不足”; “状态”:“PERMISSION_DENIED”错误
【发布时间】:2021-10-23 00:15:49
【问题描述】:

我正在尝试使用 api 向我的谷歌分析帐户中的用户授予访问权限。但我得到了

“错误”:{ “代码”:403, "message": "请求的身份验证范围不足。", “错误”:[ { “消息”:“权限不足”, “域”:“全球”, “原因”:“权限不足” } ], “状态”:“PERMISSION_DENIED” } 这个错误。 这是我的 php 代码。

<?php
include('config.php');

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://analytics.googleapis.com/analytics/v3/management/accounts/203453755/entityUserLinks?key=[api key];
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id\":\"id:mailId\",\"kind\":\"analytics#entityUserLink\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/id/entityUserLinks/id:mailId\",\"entity\":{\"accountRef\":{\"id\":\"id\",\"kind\":\"analytics#accountRef\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/id\",\"name\":\"abir test\"},\"webPropertyRef\":{\"id\":\"UA-webproperty\",\"kind\":\"analytics#webPropertyRef\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/id\",\"accountId\":\"id\",\"internalWebPropertyId\":\"id\",\"name\":\"malta\"},\"profileRef\":{\"id\":\"id\",\"kind\":\"analytics#profileRef\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/id\",\"accountId\":\"accountId\",\"webPropertyId\":\"UA-webproperty\",\"internalWebPropertyId\":\"id\",\"name\":\"All Web Site Data\"}},\"userRef\":{\"kind\":\"analytics#userRef\",\"id\":\"userEmailId\",\"email\":\"usermail@gmail.com\"},\"permissions\":{\"effective\":[\"READ_AND_ANALYZE\"],\"local\":[\"READ_AND_ANALYZE\"]}}");
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

$google_client->addScope('https://www.googleapis.com/auth/analytics.manage.users');
$headers = array();
$headers[] = 'Authorization: Bearer [access_token]
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/json';

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
echo '<pre>';
var_dump($result,true);
curl_close($ch);

?>

我该如何解决这个问题?

【问题讨论】:

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


    【解决方案1】:

    您似乎正在使用Account User Links: list 方法。

    此方法需要以下范围之一的授权

    您似乎使用了正确的范围

    https://www.googleapis.com/auth/analytics.manage.users

    所以发生了两件事之一。

    您授权的用户没有管理员访问权限,因此无法看到用户自己。如果是这种情况,请使用具有管理员访问权限的用户登录或升级此用户以具有管理员访问权限。

    或者您在授权用户之后更改了应用程序中的范围。如果您确实更改了范围,那么您需要撤销用户访问权限,然后再次授权您的应用程序,您需要查看同意屏幕,并且它应该在上面说明新的范围。

    【讨论】:

      猜你喜欢
      • 2020-10-09
      • 1970-01-01
      • 1970-01-01
      • 2019-12-23
      • 2018-10-20
      • 2017-08-09
      • 1970-01-01
      • 2019-07-06
      • 2021-12-12
      相关资源
      最近更新 更多