YouTube Data API v3を利用する(PHPでリクエストを送信してみる)
PHPでリクエストを送信してみる
YouTube Data API: PHP コード サンプル でライブラリが公開されていますが、まずは自前でリクエストを送信してみます。
以下のサンプルでは、YouTube Data API の概要 にあるリクエスト例を PHPで送信し結果を出力しています。
※$API_KEY(API キー)はGoogle Developers Consoleで取得・設定しますが、 「サーバーキー」「ブラウザキー」「Androidキー」「iOSキー」の4種があります。 ここではサーバーキーを取得してIPアドレス制限を設定したものを利用しています。
サンプルコード
結果
{ "error": { "code": 403, "message": "The provided API key has an IP address restriction. The originating IP address of the call (221.112.157.234) violates this restriction.", "errors": [ { "message": "The provided API key has an IP address restriction. The originating IP address of the call (221.112.157.234) violates this restriction.", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED", "details": [ { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "API_KEY_IP_ADDRESS_BLOCKED", "domain": "googleapis.com", "metadata": { "consumer": "projects/699354398483", "callerIp": "221.112.157.234", "service": "youtube.googleapis.com" } }, { "@type": "type.googleapis.com/google.rpc.LocalizedMessage", "locale": "en-US", "message": "The provided API key has an IP address restriction. The originating IP address of the call (221.112.157.234) violates this restriction." } ] } }
Youtube API メモ Indexへ戻る