Skip to content

Instantly share code, notes, and snippets.

@Ryomasao
Last active February 14, 2017 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ryomasao/707c5e61a4989ac51c04195c3fcac157 to your computer and use it in GitHub Desktop.
Save Ryomasao/707c5e61a4989ac51c04195c3fcac157 to your computer and use it in GitHub Desktop.
とりあえずリクエスト
'''
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