通过Google Indexing API获取数据时出现403禁止错误

时间:2019-10-15 05:47:04

标签: api indexing

我正在使用以下代码通过索引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对象([reasonPhrase:GuzzleHttp \ Psr7 \ Response:private] =>禁止的[statusCode:GuzzleHttp \ Psr7 \ Response:private] => 403 [headers:GuzzleHttp \ Psr7 \ Response:private > Array([Vary] => Array([0] => X-Origin 1 => Referer [2] => Origin,Accept-Encoding)[Content-Type] => Array([0] => application / json ; charset = UTF-8)[Date] => Array([0] => Mon,14 Oct 2019 13:23:36 GMT)[Server] => Array([0] => ESF)[Cache-Control] =>数组([0] => private)[X-XSS-Protection] =>数组([0] => 0)[X-Frame-Options] =>数组([0] => SAMEORIGIN)[X- Content-Type-Options] =>数组([0] => nosniff)[Alt-Svc] =>数组([0] => quic =“:443”; ma = 2592000; v =“ 46,43”, h3-Q048 =“:443”; ma = 2592000,h3-Q046 =“:443”; ma = 2592000,h3-Q043 =“:443”; ma = 2592000)[接受范围] =>数组([0 ] => none)[Transfer-Encoding] => Array([0] => chunked))[headerNames:GuzzleHttp \ Psr7 \ Response:private] => Array([vary] => Vary [content-type] =>内容类型[日期] =>日期[服务器] =>服务er [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-ranges] =>接受范围[transfer-encoding] => Transfer-Encoding)[protocol:GuzzleHttp \ Psr7 \ Response:private] = > 1.1 [stream:GuzzleHttp \ Psr7 \ Response:private] => GuzzleHttp \ Psr7 \ Stream对象([stream:GuzzleHttp \ Psr7 \ Stream:private] =>资源ID#73 [size:GuzzleHttp \ Psr7 \ Stream:private] => [seekable:GuzzleHttp \ Psr7 \ Stream:private] => 1 [可读:GuzzleHttp \ Psr7 \ Stream:private] => 1 [writable:GuzzleHttp \ Psr7 \ Stream:private] => 1 [uri:GuzzleHttp \ Psr7 \ Stream:private] => php:// temp [customMetadata:GuzzleHttp \ Psr7 \ Stream:private] => Array()))

谢谢, 阿比舍克

0 个答案:

没有答案