Before you can use the Cloud Vision API, you must enable it for your project:
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
In the Cloud Console, on the project selector page, select or create a Cloud project.
Make sure that billing is enabled for your Google Cloud project. Learn how to confirm billing is enabled for your project.
- Enable the Cloud Vision API.
Set up authentication:
In the Cloud Console, go to the Create service account key page.Go to the Create Service Account Key page
- From the Service account list, select New service account.
- In the Service account name field, enter a name.
From the Role list, select Project > Owner.Note: The Role field authorizes your service account to access resources. You can view and change this field later by using the Cloud Console. If you are developing a production app, specify more granular permissions than Project > Owner. For more information, see granting roles to service accounts.
- Click Create. A JSON file that contains your key downloads to your computer.
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.
Example: Linux or macOS
Replace [PATH] with the path of the JSON file that contains your service account key.
Replace [PATH] with the path of the JSON file that contains your service account key, and [FILE_NAME] with the filename.
With command prompt: