php | Google 网站管理员 API 服务帐户没有权限
php | Google Webmaster API Service Account has no permission
我正在使用以下代码从搜索控制台获取我网站的统计信息:
$client = new Google_Client();
$creds = $client->loadServiceAccountJson('---JSON FILE---', 'https://www.googleapis.com/auth/webmasters.readonly');
$client->setAssertionCredentials($creds);
$service = new Google_Service_Webmasters($client);
$ressource = $service->searchanalytics;
$options = new Google_Service_Webmasters_SearchAnalyticsQueryRequest();
$options->setStartDate('2015-11-11');
$options->setEndDate('2015-11-11');
try{
$response = $ressource->query('http://www.example.com/', $options);
} catch (Exception $e){
echo $e->getMessage();
}
我使用 google 服务帐户授权 api 调用,但出现错误:
Error calling POST https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Fwww.example.com%2F/searchAnalytics/query: (403) User does not have sufficient permission for site 'http*://www.example.com/'. See also: https://support.google.com/webmasters/answer/2451999.
我还以所有者身份将服务帐户的电子邮件地址添加到我的搜索控制台 属性,但错误仍然存在。我不知道了,我做错了什么?
检查 属性 是否列在站点列表中:https://developers.google.com/webmaster-tools/v3/sites/list
仔细检查 属性 url 中的 https 和 www。
所以问题正在解决中!
问题是首先您必须将服务帐户添加到搜索控制台 属性,然后授予它权限,然后让他成为所有者,您不会再遇到权限错误!
在这里找到了解决方案:
我正在使用以下代码从搜索控制台获取我网站的统计信息:
$client = new Google_Client();
$creds = $client->loadServiceAccountJson('---JSON FILE---', 'https://www.googleapis.com/auth/webmasters.readonly');
$client->setAssertionCredentials($creds);
$service = new Google_Service_Webmasters($client);
$ressource = $service->searchanalytics;
$options = new Google_Service_Webmasters_SearchAnalyticsQueryRequest();
$options->setStartDate('2015-11-11');
$options->setEndDate('2015-11-11');
try{
$response = $ressource->query('http://www.example.com/', $options);
} catch (Exception $e){
echo $e->getMessage();
}
我使用 google 服务帐户授权 api 调用,但出现错误:
Error calling POST https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Fwww.example.com%2F/searchAnalytics/query: (403) User does not have sufficient permission for site 'http*://www.example.com/'. See also: https://support.google.com/webmasters/answer/2451999.
我还以所有者身份将服务帐户的电子邮件地址添加到我的搜索控制台 属性,但错误仍然存在。我不知道了,我做错了什么?
检查 属性 是否列在站点列表中:https://developers.google.com/webmaster-tools/v3/sites/list
仔细检查 属性 url 中的 https 和 www。
所以问题正在解决中!
问题是首先您必须将服务帐户添加到搜索控制台 属性,然后授予它权限,然后让他成为所有者,您不会再遇到权限错误!
在这里找到了解决方案: