3

I'm using the api sample as found here.

Running gcloud config list shows my default project as project = multichoice-insights

Important extract of the code shows that I get the default credentials:

  credentials = GoogleCredentials.get_application_default().create_scoped(
  ['https://www.googleapis.com/auth/cloud-platform'],
)

However, when I try and use the api, I get the error message:

googleapiclient.errors.HttpError: <HttpError 403 when requesting 
https://language.googleapis.com/v1beta1/documents:analyzeSentiment?
alt=json returned "Google Cloud Natural Language API has not been used 
in project google.com:cloudsdktool before or it is disabled. Enable it 
by visiting
   https://console.developers.google.com/apis/api/language.googleapis.com/over
view?project=google.com:cloudsdktool then retry. If you enabled this 
API recently, wait a few minutes for the action to propagate to our 
systems and retry.">

I think this shows that the project used: project=google.com:cloudsdktool

How can I change this to project-name?

I have enabled this api in the console.

Daniel Lee
  • 7,189
  • 2
  • 26
  • 44

1 Answers1

3

For anyone that has this issue:

One needs to set their Environment variable. If you are using virtualenvs, set the variable as follows.

In the file: .virtualenvs/env_name/bin edit the file activate to contain the following line:

GOOGLE_APPLICATION_CREDENTIALS=/abs/path/to/credentials.json

This credentials.json is donwloaded from the api page. Full instructions can be gathered from here

Hope this helps someone.

Daniel Lee
  • 7,189
  • 2
  • 26
  • 44
  • Setting the GOOGLE_APPLICATION_CREDENTIALS env var didn't fix the issue in my case ... It does work in production (AppEngine) but can't run in dev ... anyone else having the same issue? – Neurus Dec 07 '16 at 22:11
  • try unset your env var with `unset GOOGLE_APPLICATION_CREDENTIALS` and then try this `gcloud auth application-default login` Will be interesting to see whether this works. – Daniel Lee Dec 08 '16 at 06:42