2016-11-04 90 views
1

我使用的API示例为here无法在Cloud Natural Language中设置项目API

运行gcloud config list显示我的默认项目为project = multichoice-insights

重要的代码摘录显示,我得到了默认凭据:

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

然而,当我尝试使用API​​,我得到的错误消息:

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."> 

我认为,这显示使用的项目:project=google.com:cloudsdktool

我该如何将其更改为project-name

我已经在控制台中启用了这个api。

回答

2

对于有此问题的人:

需要设置其环境变量。如果您使用的是virtualenvs,请按如下所示设置变量。

在文件:.virtualenvs/env_name/bin编辑文件启动以包含以下行:

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

这credentials.json从API页面donwloaded。完整的说明可以从here

希望这可以帮助别人。

+0

设置GOOGLE_APPLICATION_CREDENTIALS env var在我的情况下没有解决问题......它在生产(AppEngine)中工作,但不能在开发中运行......任何其他人都有相同的问题? – Neurus

+0

尝试使用'未设置GOOGLE_APPLICATION_CREDENTIALS'取消设置您的env var,然后尝试使用'gcloud auth application-default login' 有趣的是看看它是否有效。 –

相关问题