【问题标题】:php | Google Webmaster API Service Account has no permissionphp | Google 站长 API 服务帐号没有权限
【发布时间】:2015-11-14 11:53:13
【问题描述】:

我正在使用以下代码从搜索控制台获取我网站的统计信息:

$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 调用,但它给了我错误:

调用 POST https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Fwww.example.com%2F/searchAnalytics/query 时出错:(403) 用户对站点“http*://www.example.com/”没有足够的权限。另见:https://support.google.com/webmasters/answer/2451999

我还以所有者身份将服务帐户的电子邮件地址添加到了我的搜索控制台属性中,但错误仍然存​​在。我不知道了,我做错了什么?

【问题讨论】:

    标签: php google-search-console service-accounts google-client


    【解决方案1】:

    所以问题正在解决!

    问题是首先你必须将服务帐户添加到搜索控制台属性,然后授予它权限,然后将他设置为所有者,你不会再次获得权限错误!

    在这里找到解决方案: Google Webmasters API for Java returns empty site list

    【讨论】:

      【解决方案2】:

      检查该属性是否在站点列表中:https://developers.google.com/webmaster-tools/v3/sites/list

      在属性 url 中仔细检查 https 和 www。

      【讨论】:

      • 感谢您的回答。响应是一个空数组 SiteEntry,我的站点应该在其中列出。这很奇怪,因为我在搜索控制台中将服务帐户列为站点所有者。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-07
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多