Я использую следующий код для получения данных через API индексации и сделал учетную запись службы также в качестве владельца, но даже тогда я получаю следующую ошибку. Пожалуйста, дайте мне знать.
require_once '../google-api-php-client-2.2.2/vendor/autoload.php';
$client = new Google_Client();
$client->setDeveloperKey('xxxxxxxxxxxxxx');
$client->setAuthConfig('xxxxxxxxxxxxx.json');
$client->addScope('https://www.googleapis.com/auth/indexing');
$httpClient = $client->authorize();
$endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish?key=xxxxxxxxxx';
$content = "{
\"url\": \"https://www.example.com/whatever.html\",
\"type\": \"URL_UPDATED\"
}";
$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();
print_r($response);
Получение следующей ошибки
GuzzleHttp \ Psr7 \ Response Object ([reasonPhrase: GuzzleHttp \ Psr7 \ Response: private] => Запрещено [statusCode: GuzzleHttp \ Psr7\ Response: private] => 403 [заголовки: GuzzleHttp \ Psr7 \ Response: private] => Array ([Vary] => Array ([0] => X-Origin 1 => Referer [2] => Origin, Accept)-Кодирование) [Content-Type] => Array ([0] => application / json; charset = UTF-8) [Date] => Array ([0] => Понедельник, 14 октября 2019 13:23:36 GMT) [Server] => Массив ([0] => ESF) [Cache-Control] => Массив ([0] => частный) [X-XSS-Protection] => Массив ([0] => 0) [X-Frame-Options] => Array ([0] => SAMEORIGIN) [X-Content-Type-Options] => Array ([0] => nosniff) [Alt-Svc] => Array ([0] => quic = ": 443"; ma = 2592000; v = "46,43", h3-Q048 = ": 443"; ma = 2592000, h3-Q046 = ": 443"; ma = 2592000, h3-Q043 =": 443"; ma = 2592000) [Accept-Ranges] => Array ([0] => none) [Transfer-Encoding] => Array ([0] => chunked)) [headerNames: GuzzleHttp \ Psr7 \ Response: private] => Array ([варьируется] => Vary [content-type] => Content-Type [date] => Date [server] => Сервер [cache-control] => Cache-Control [x-xss-protection] => X-XSS-Protection[x-frame-options] => X-Frame-Options [x-content-type-options] => X-Content-Type-Options [alt-svc] => Alt-Svc [accept-range] => Принять-Ranges [Transfer-Encoding] => Transfer-Encoding) [протокол: GuzzleHttp \ Psr7 \ Response: private] => 1.1 [stream: GuzzleHttp \ Psr7 \ Response: private] => GuzzleHttp \ Psr7 \ Stream Object ([поток:GuzzleHttp \ Psr7 \ Stream: private] => Идентификатор ресурса # 73 [размер: GuzzleHttp \ Psr7 \ Stream: private] => [seekable: GuzzleHttp \ Psr7 \ Stream: private] => 1 [читаемый: GuzzleHttp \ Psr7 \ Stream:private] => 1 [доступный для записи: GuzzleHttp \ Psr7 \ Stream: private] => 1 [uri: GuzzleHttp \ Psr7 \ Stream: private] => php: // temp [customMetadata: GuzzleHttp \ Psr7 \ Stream: private] =>Array ()))
Спасибо, Абхишек