Last active
February 14, 2017 13:22
-
-
Save Ryomasao/707c5e61a4989ac51c04195c3fcac157 to your computer and use it in GitHub Desktop.
とりあえずリクエスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
CloudVisonを使って遊んでみる | |
APIに画像を渡し、結果をJSON形式で受け取る | |
''' | |
#リクエスト処理に必要なライブラリ | |
import requests | |
#CloudVisonのAPI keyにAPIキーを渡す。 | |
API_URL = 'https://vision.googleapis.com/v1/images:annotate?key=' | |
#APIのキー https://console.cloud.google.com で確認する。 | |
API_KEY = 'himitu' | |
#実際にリクエストを投げる機能が必要。 | |
r = requests.post(API_URL+API_KEY) | |
print(r.text) | |
''' | |
API_KEYを適当なものにすると、以下のエラーがAPI側から返ってくる。 | |
ということは、リクエスト処理自体はうまくいっていそう。 | |
{ | |
"error": { | |
"code": 400, | |
"message": "API key not valid. Please pass a valid API key.", | |
"status": "INVALID_ARGUMENT", | |
"details": [ | |
{ | |
"@type": "type.googleapis.com/google.rpc.Help", | |
"links": [ | |
{ | |
"description": "Google developers console", | |
"url": "https://console.developers.google.com" | |
} | |
] | |
} | |
] | |
} | |
} | |
正しいAPI_KEYでリクエストすると、レスポンスは{} 空っぽで返ってくる。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment