0

我想在“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 中添加服务帐户电子邮件地址。

我们的代码有什么问题?

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

4

0 回答 0