質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Q&A

0回答

2075閲覧

Indexing APIで403エラーが表示されています。

yyanagi

総合スコア0

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

0グッド

0クリップ

投稿2020/09/25 05:40

前提・実現したいこと

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問