【发布时间】:2021-01-28 21:34:08
【问题描述】:
您好,我正在尝试使用 Google 索引 API。我使用了这个教程 - https://developers.google.com/search/apis/indexing-api/v3/prereqs
我使用了这个 php 库 - 不同的分支 - v1-master 因为我不使用 composer 所以我不得不使用 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 加载
但我收到错误未捕获的 Google_Exception:无效的客户端机密 JSON 文件。
这个话题与-google-api-php-client: Invalid client secret JSON file有关
但我无法解决它,我被卡住了
【问题讨论】:
标签: php json google-indexing-api