6

我想执行示例中的代码:

    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();

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

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

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

回答

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

4

2 回答 2

5

As mentioned, your service account should be "owner" (not "full"). With the new search console, it is almost impossible to set the service account to Owner, luckily, you can use the old Webmasters tool.

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

于 2020-04-08T17:09:19.653 回答
2

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

于 2020-04-08T14:39:32.607 回答