Before you begin
-
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 Google Cloud project.
-
Verifica che la fatturazione sia attivata per il tuo progetto.
- 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_CREDENTIALS to the file 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.
Install the client library
C#
For more on setting up your C# development environment, refer to the C# Development Environment Setup Guide.Install-Package Google.Cloud.Vision.V1 -Pre
Go
go get -u cloud.google.com/go/vision/apiv1
Java
For more on setting up your Java development environment, refer to the Java Development Environment Setup Guide. If you are using Maven, add the following to yourpom.xml
file:
If you are using Gradle, add the following to your
dependencies:
If you are using SBT, add the following to your
dependencies:
If you're using IntelliJ or Eclipse, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
Node.js
For more on setting up your Node.js development environment, refer to the Node.js Development Environment Setup Guide.npm install --save @google-cloud/vision
PHP
composer require google/cloud-vision
Python
For more on setting up your Python development environment, refer to the Python Development Environment Setup Guide.pip install --upgrade google-cloud-vision
Ruby
For more on setting up your Ruby development environment, refer to the Ruby Development Environment Setup Guide.gem install google-cloud-vision
Label detection
Now you can use the Vision API to request information from an image, such as label detection. Run the following code to perform your first image label detection request:
C#
Before trying this sample, follow the C# setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API C# API reference documentation .
Go
Before trying this sample, follow the Go setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Go API reference documentation .
Java
Before trying this sample, follow the Java setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Java API reference documentation .
Node.js
Before trying this sample, follow the Node.js setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Node.js API reference documentation .
PHP
Before trying this sample, follow the PHP setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API PHP API reference documentation .
Python
Before trying this sample, follow the Python setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Python API reference documentation .
Ruby
Before trying this sample, follow the Ruby setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Ruby API reference documentation .
Congratulations! You've sent your first request to Vision API.
How did it go?
Clean up
To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:
- Use the Cloud Console to delete your project if you do not need it.
What's next
Find out more about our Cloud Vision API Client Libraries.