【发布时间】: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