我想从示例中执行代码:
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所有权。”
要获得访问权限,还需要做些什么并检查?
答案 0 :(得分:1)
完全访问权限!==所有者。我需要更好地阅读文档。
答案 1 :(得分:1)
如上所述,您的服务帐户应为“所有者”(不是“完整”)。 使用新的搜索控制台,几乎不可能将服务帐户设置为“所有者”,幸运的是,您可以使用old Webmasters tool。