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。
設置GOOGLE_APPLICATION_CREDENTIALS env var在我的情況下沒有解決問題......它在生產(AppEngine)中工作,但不能在開發中運行......任何其他人都有相同的問題? – Neurus
嘗試使用'未設置GOOGLE_APPLICATION_CREDENTIALS'取消設置您的env var,然後嘗試使用'gcloud auth application-default login' 有趣的是看看它是否有效。 –