1

我正在尝试将 google index API 与我的网站集成以索引我的身边,但我收到 401 错误。我搜索并为我的问题找到了这个解决方案。 Google Indexing API - 403 'Forbidden Response' 但这在我的情况下也不起作用,因为我已经验证我是 google 搜索控制台的所有者,并且集成了正确的 JSON 身份验证文件。我正在检查索引矩阵,但在我的控制台平台上获得了所有的调用次数。

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",
  "type": "URL_UPDATED"
}';

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

任何帮助将不胜感激。预先感谢

4

0 回答 0