【发布时间】:2016-04-12 10:10:23
【问题描述】:
我似乎无法在我的谷歌云视觉代码中找到添加 API 密钥的位置或我需要定位到谷歌凭据文件的位置:
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 密钥或找到凭据文件?
编辑:添加了 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 ......你如何尝试运行请插入问题。检查这个问题:stackoverflow.com/questions/30638974/…
标签: python google-cloud-vision