私は、APIキーを追加する場所を見つけることができないようまたは私はGoogleの資格情報を検索する必要がある場所に私のGoogleのクラウドビジョンコードでファイル:GoogleクラウドビジョンAPI - Pythonの
import argparse
import base64
import httplib2
import validators
import requests
from apiclient.discovery import build
from oauth2client.client import GoogleCredentials
def main(photo_file):
'''Run a label request on a single image'''
API_DISCOVERY_FILE = 'https://vision.googleapis.com/$discovery/rest?version=v1'
http = httplib2.Http()
credentials = GoogleCredentials.get_application_default().create_scoped(
['https://www.googleapis.com/auth/cloud-platform'])
credentials.authorize(http)
service = build('vision', 'v1', http, discoveryServiceUrl=API_DISCOVERY_FILE)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'image_file', help='The image you\'d like to label.')
args = parser.parse_args()
main(args.image_file)
photo_file = "image_of_bottle.jpg"
main(photo_file)
誰もが知っていますどこでAPIキーを追加したり、資格情報ファイルを見つけることができますか?
EDIT:Eray Balkanliの推奨する変更が追加され、画像ファイルが追加されました。
import argparse
import base64
import httplib2
import validators
import requests
from apiclient.discovery import build
from oauth2client.client import GoogleCredentials
def main(photo_file,developerkey):
'''Run a label request on a single image'''
API_DISCOVERY_FILE = 'https://vision.googleapis.com/$discovery/rest?version=v1'
http = httplib2.Http()
credentials = GoogleCredentials.get_application_default().create_scoped(
['https://www.googleapis.com/auth/cloud-platform'])
credentials.authorize(http)
service = build('vision', 'v1', http, discoveryServiceUrl=API_DISCOVERY_FILE,developerkey=INSERT API KEY)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'image_file', help='The image you\'d like to label.')
args = parser.parse_args()
main(args.image_file)
photo_file = "image_file.jpg"
main(photo_file,developerkey)
を私は次のエラーを受け取った:
usage: googleimagetest_v.4.py [-h] image_file
googleimagetest_v.4.py: error: too few arguments
誰もが、私はこのエラーを解決する方法を知っています私は、私はそれを正しくやったかどうかわからないんだけど?
あなたのクラスがどのくらい正確に走っているのか聞いてみました。このクラスを実行する必要があります:$ python googleimagetest_v.4.py image_file ......どのように実行しようとしていますか質問を挿入してください。この質問をチェックする:http://stackoverflow.com/questions/30638974/google-prediction-api-hello-prediction-error-to-few-arguments –
pythonの例を見てきましたかhttps://github.com/GoogleCloudPlatform/cloud-vision/tree/master/python?この例には、資格情報の設定に関する情報があります。https://github.com/GoogleCloudPlatform/cloud-vision/tree/master/python/landmark_detection/ –