2016-03-07 130 views
4

嗨,我嘗試使用谷歌的雲計算願景API,具體的例子:https://cloud.google.com/vision/docs/label-tutorial#label_tutorial_1Google Cloud vision API:「請求的認證範圍不足。」

我跟着這個教程:https://cloud.google.com/vision/docs/getting-started#set_up_a_service_account設立一個服務帳戶,但是當我跑我的代碼,我得到:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://vision.googleapis.com/$discovery/rest?version=v1 returned "Request had insufficient authentication scopes."> 

任何人都可以幫忙嗎?我無法弄清楚發生了什麼,我的代碼與教程是1:1。

回答

3

我得到了同樣的錯誤。我做了以下內容:

sudo apt-get update & apt-get upgrade 

pip install --upgrade google-api-python-client 

然後初始化gcloud SDK通過......

gcloud init 

,瞧它開始工作!

您也可以嘗試重新生成的憑證從API管理

5

您需要從您的電腦清潔~/.credentials/sheets.googleapis.com-python-quickstart.json。然後將您的範圍定義爲https://www.googleapis.com/auth/drive。再次運行您的代碼,它應該要求您重新授權。然後運行你的代碼。

0

您可能希望使用Vision API的google.cloud client library

要使用正確的範圍進行身份驗證,您需要在雲控制檯中生成一個服務帳戶,並從您的代碼(或環境變量)中指向它。有關詳細信息,請參見​​:

從雲控制檯中的credentials manager獲取服務帳戶。然後指向你的項目和JSON憑據在你的環境文件:

$ export GOOGLE_CLOUD_PROJECT="your-project-id-here" 
$ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json" 

你試圖運行(標記的圖像)演示變成:

>>> from google.cloud import vision 
>>> client = vision.Client() 
>>> image = client.image(source_uri='gs://my-storage-bucket/image.jpg') 
>>> labels = image.detect_labels(limit=3) 
>>> labels[0].description 
'automobile' 
>>> labels[0].score 
0.9863683 

(代碼片段從 docs拍攝)
相關問題