索引 API 403 权限被拒绝。无法验证 URL 所有权

WP *_*unk 6 indexing google-api google-indexing-api

我想执行示例中的代码:

    require_once 'google-api-php-client/vendor/autoload.php';

    $client = new Google_Client();

    // service_account_file.json is the private key that you created         for your service account.
    $client->setAuthConfig('service_account_file.json');
    $client->addScope('https://www.googleapis.com/auth/indexing');

    // Get a Guzzle HTTP Client
    $httpClient = $client->authorize();
    $endpoint =         'https://indexing.googleapis.com/v3/urlNotifications:publish';

    // Define contents here. The structure of the content is described in the next step.
    $content = "{
      \"url\": \"http://example.com/jobs/42\", //I used real url from my homepage
      \"type\": \"URL_UPDATED\"
    }";

    $response = $httpClient->post($endpoint, [ 'body' => $content ]);
    $status_code = $response->getStatusCode();
Run Code Online (Sandbox Code Playgroud)

但作为回应,我收到一个错误:403“权限被拒绝。无法验证 URL 所有权。”。

  1. 我创建了服务帐户并在我的应用程序中读取了该文件。
  2. 网站已验证。屏幕1
  3. 访问服务帐户已满。屏幕2
  4. 我在搜索控制台和我的应用程序中使用了没有“www”和 https 的域。
  5. 启用索引 API 和请求。

还需要做什么和检查才能获得访问权限?

回答

完全访问!== 所有者。我需要更好地阅读文档。

Rod*_*lho 5

如前所述,您的服务帐户应该是“所有者”(而不是“完整”)。使用新的搜索控制台,将服务帐户设置为 Owner 几乎是不可能的,幸运的是,您可以使用旧的 Webmasters 工具

https://support.google.com/webmasters/thread/4763732?hl=en


WP *_*unk 3

完全访问权限!== 所有者。我需要更好地阅读文档。