无法在 Cloud Natural Language 中设置项目 API
Can't set project in Cloud Natural Language API
我正在使用找到的 api 示例 here。
运行 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。
遇到此问题的任何人:
需要设置他们的环境变量。如果您使用的是 virtualenvs,请按如下方式设置变量。
在文件中:.virtualenvs/env_name/bin
编辑激活文件以包含以下行:
GOOGLE_APPLICATION_CREDENTIALS=/abs/path/to/credentials.json
此 credentials.json 是从 api 页面下载的。可以从 here
收集完整说明
希望这对某人有所帮助。
我正在使用找到的 api 示例 here。
运行 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。
遇到此问题的任何人:
需要设置他们的环境变量。如果您使用的是 virtualenvs,请按如下方式设置变量。
在文件中:.virtualenvs/env_name/bin
编辑激活文件以包含以下行:
GOOGLE_APPLICATION_CREDENTIALS=/abs/path/to/credentials.json
此 credentials.json 是从 api 页面下载的。可以从 here
收集完整说明希望这对某人有所帮助。