Hi,
I am a bit lost on the how to integrate the vision api into my android (java) projects.
- I have add the :
implementation ‘com.google.cloud:google-cloud-vision:3.40.0’
to my project.
- I have created the new project in the google cloud platform.
- I have enabled the VISON APIin the google cloud platform.
- I have created in the credentials tab a Service Account.
from this point I am a bit lost, I get error:
2024-04-30 07:50:59.045 4388-4388 System.out com.example.zukitscan I line 234: java.io.IOException: Your default credentials were not found. To set up Application Default Credentials for your environment, see https://cloud.google.com/docs/authentication/external/set-up-adc
- I followed that link of guidance and I got the:
application_default_credentials.json
From here what’s next ? how do I link this file into my android project ?
Please help.
Thanks.
1 Like
Hello @YanivBelo ,
you can specify the path to the application_default_credentials.json file in your code to authenticate your Vision API requests.
For example:
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.vision.v1.ImageAnnotatorClient;
import com.google.cloud.vision.v1.ImageAnnotatorSettings;
import java.io.FileInputStream;
import java.io.IOException;
public class VisionAPIUtil {
public static ImageAnnotatorClient createImageAnnotatorClient() throws IOException {
// Specify the path to your credentials JSON file
String credentialsPath = “<path/to/your/credentials/file>”;
// Load the credentials
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(credentialsPath));
// Create the ImageAnnotatorClient with the credentials
ImageAnnotatorSettings settings = ImageAnnotatorSettings.newBuilder()
.setCredentialsProvider(() → credentials)
.build();
return ImageAnnotatorClient.create(settings);
}
}