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 所有权。”。
还需要做什么和检查才能获得访问权限?
回答
完全访问!== 所有者。我需要更好地阅读文档。
如前所述,您的服务帐户应该是“所有者”(而不是“完整”)。使用新的搜索控制台,将服务帐户设置为 Owner 几乎是不可能的,幸运的是,您可以使用旧的 Webmasters 工具。
https://support.google.com/webmasters/thread/4763732?hl=en
归档时间: |
|
查看次数: |
1169 次 |
最近记录: |