前提・実現したいこと
PHPでIndexing APIを利用して求人情報をクローリングさせたいです。
composerでGoogleAPIのライブラリをダウンロードし
Xamppでテストしているところです。
発生している問題・エラーメッセージ
レスポンスをprint_rで吐き出した結果です。
Forbidden 403 となっているようです。
GuzzleHttp\Psr7\Response Object ( [reasonPhrase:GuzzleHttp\Psr7\Response:private] => Forbidden [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] => Fri, 25 Sep 2020 04:50:49 GMT ) [Server] => Array ( [0] => ESF ) [Cache-Control] => Array ( [0] => private ) [X-XSS-Protection] => Array ( [0] => 0 ) [X-Frame-Options] => Array ( [0] => SAMEORIGIN ) [X-Content-Type-Options] => Array ( [0] => nosniff ) [Alt-Svc] => Array ( [0] => h3-Q050=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" ) [Accept-Ranges] => Array ( [0] => none ) [Transfer-Encoding] => Array ( [0] => chunked ) ) [headerNames:GuzzleHttp\Psr7\Response:private] => Array ( [vary] => Vary [content-type] => Content-Type [date] => Date [server] => 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-ranges] => Accept-Ranges [transfer-encoding] => Transfer-Encoding ) [protocol:GuzzleHttp\Psr7\Response:private] => 1.1 [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object ( [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #91 [size:GuzzleHttp\Psr7\Stream:private] => [seekable:GuzzleHttp\Psr7\Stream:private] => 1 [readable:GuzzleHttp\Psr7\Stream:private] => 1 [writable:GuzzleHttp\Psr7\Stream:private] => 1 [uri:GuzzleHttp\Psr7\Stream:private] => php://temp [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array ( ) ) )
該当のソースコード
PHP
1require_once 'vendor/autoload.php'; 2 3$client = new Google_Client(); 4 5// service_account_file.json is the private key that you created for your service account. 6$client->setAuthConfig('***********.json'); 7$client->addScope('https://www.googleapis.com/auth/indexing'); 8 9// Get a Guzzle HTTP Client 10$httpClient = $client->authorize(); 11$endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish'; 12 13// Define contents here. The structure of the content is described in the next step. 14$content = "{ 15 \"url\": \"https://*********.com/\", 16 \"type\": \"URL_UPDATED\" 17}"; 18 19$response = $httpClient->post($endpoint, [ 'body' => $content ]); 20$status_code = $response->getStatusCode(); 21 22print_r($response);
試したこと
https://developers.google.com/search/apis/indexing-api/v3/quickstart?hl=ja
上記に沿って試しているところです。
https://developers.google.com/search/apis/indexing-api/v3/reference/indexing/rest/v3/urlNotifications/publish
上記でAPIをテストしてみた結果、問題なく200が返ってきました。
APIには問題ないのかと思っています。
補足情報(FW/ツールのバージョンなど)
Windows10
PHP Version 5.6.28
あなたの回答
tips
プレビュー