Reputation: 381
I'm trying to usethe Cloud Natural Language API with the code given in this link. (first or second) link
I get the below error.
google.api_core.exceptions.PermissionDenied: 403 Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are nots
upported by the language.googleapis.com. We recommend configuring the billing/quota_project setting in gcloud or using a service account through the auth/impersonate_service
_account setting. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.
I know that we need to give the json file of the service account key in the code as per google doc (link). But it does not say about handling the API Key. Also isn't it not recommended to give API Key in code. So what is the way?
I tried using the Curl command with the API Key and it works fine.
curl "https://language.googleapis.com/v1/documents:analyzeEntities?key=${API_KEY}" -s -X POST -H "Content-Type: applicat
ion/json" --data-binary @request.json
However i dont know how to incorporate the API Key (which i have) into the code present in the first link i posted above.
Upvotes: 0
Views: 684
Reputation: 14759
Did you go through all the steps provided by Google? You probably missed one of the steps outlined below.
Create a project in GCP.
Enable billing for that project.
Enable the Natural Language API in that project.
gcloud services enable language.googleapis.com --project [PROJECT_ID]
Use your own account OR a service account key (with owner permissions).
gcloud auth application-default login
OR
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"
Set the project id trough the command line.
gcloud config set project [PROJECT_ID]
Upvotes: 0