I can't seem to find where to add the API key or where I need to locate to the google credentials file in my google cloud vision code:
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)
Does anyone know where I can add the API key or locate to the credentials file?
EDIT: Added changes recommended by Eray Balkanli and I added my image file in the call. I'm not sure if I did it correctly:
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)
I received the following error:
usage: googleimagetest_v.4.py [-h] image_file
googleimagetest_v.4.py: error: too few arguments
Does anyone know how I can solve this error?