您好我正在尝试使用 Google 索引 API。我使用了本教程 - https://developers.google.com/search/apis/indexing-api/v3/prereqs
我使用了这个 php 库 - 不同的分支 - v1-master 因为我不使用作曲家所以我不得不使用 autoload.php https://github.com/googleapis/google-api-php-client/tree/master
这是我的代码:
require_once($_SERVER["DOCUMENT_ROOT"] . '/assets/google-api-php-client/src/Google/autoload.php');
require_once($_SERVER["DOCUMENT_ROOT"] . '/assets/google-api-php-client/examples/templates/base.php');
$client = new Google_Client();
// service_account_file.json is the private key that you created for your service account.
$client->setAuthConfig($_SERVER["DOCUMENT_ROOT"] . '/assets/google-api-php-client/serviceAccount');
$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();
- 我创建了服务帐户
- 下载的服务帐户 json 文件 这是 json 的样子
- 如上所示,添加了 json 的路径
- 我在 console.developers.google.com 中为我的项目启用了 Indexing API
- json 加载
但我收到错误Uncaught Google_Exception: Invalid client secret JSON file。
本主题与 - google-api-php-client: Invalid client secret JSON file
但我就是无法解决它,我被困住了