2017-07-15 76 views
4

當我們返回「我們目前無法訪問URL」時,我打電話給google api。但資源必須存在並且可以被訪問。「我們目前無法訪問URL。」

https://vision.googleapis.com/v1/images:annotate

請求內容:

{ 
    "requests": [ 
    { 
     "image": { 
     "source": { 
      "imageUri": "http://yun.jybdfx.com/static/img/homebg.jpg" 
     } 
     }, 
     "features": [ 
     { 
      "type": "TEXT_DETECTION" 
     } 
     ], 
     "imageContext": { 
     "languageHints": [ 
      "zh" 
     ] 
     } 
    } 
    ] 
} 

響應內容:

{ 
    "responses": [ 
    { 
     "error": { 
     "code": 4, 
     "message": "We can not access the URL currently. Please download the content and pass it in." 
     } 
    } 
    ] 
} 

回答

0

非常同樣的要求對我的作品。圖像主機可能暫時關閉和/或有問題。如果您重試請求,它將主要爲您工作。

0

截至2017年8月,這是Google Cloud Vision API(source)的一個已知問題。它似乎爲一些用戶重播,但不是確定性的,我用很多圖像自己碰到它。

當前的解決方法包括將您的內容上傳到Google Cloud Storage並傳遞它的gs:// uri(注意它不必在GCS上公開可讀),或者在本地下載圖像並將其傳遞到base64的vision API格式。

下面是後一種方法的Node.js的一個例子:

const request = require('request-promise-native').defaults({ 
    encoding: 'base64' 
}) 

const data = await request(image) 

const response = await client.annotateImage({ 
    image: { 
    content: data 
    }, 
    features: [ 
    { type: vision.v1.types.Feature.Type.LABEL_DETECTION }, 
    { type: vision.v1.types.Feature.Type.CROP_HINTS } 
    ] 
}) 
0

對我的作品只上傳圖片添加到Google雲計算平臺,並把它傳遞給URI參數。