在Google Indexing API上出现403错误

时间:2019-05-15 07:34:32

标签: php google-api google-api-php-client service-accounts google-indexing-api

我要在“ Google Indexing API”代码上执行。

<?php
require_once 'google-api-php-client-2.2.2/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.html\",
  \"type\": \"URL_UPDATED"
}';

$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();

echo $status_code;
?>

但作为回应,我收到一个错误:403。

我在服务帐户上创建的网站验证已完成

我想在Google Search Console中添加服务帐户的电子邮件地址。

我们的代码有什么问题?

感谢任何帮助和想法。谢谢!

0 个答案:

没有答案