google Cloud Vision API:vision.detectText() 不接受 google 驱动器 v3 URI

google Cloud Vision API: vision.detectText() does not accept a google drive v3 URI

vision.detectText() 在递交由 google 驱动器 v3 以从 drive.files.get()

获得的 webviewLink 格式呈现的 URI 时阻塞

我的 webViewLink 抓取器是:

drive.files.get({
  auth: auth,
  fileId: options.fileID,
  //fields: 'webContentLink'  // <-- downloads the file
  fields: 'webViewLink'       // <-- "views" the file
},function(err, response) {}

response.webViewLink 的格式为:

https://drive.google.com/file/d/0Bw4DMtLCtPMkOTlXR1l4Nkw1WGs/view?usp=drivesdk

vision.detectText(response.webViewLink) 窒息:

ERROR: { PartialFailureError: A failure occurred during this request.
at /Users/node_modules/@google-cloud/vision/src/index.js:434:15
at /Users/node_modules/@google-cloud/vision/src/index.js:126:5
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
errors: 
[ { image:  'https://drive.google.com/file/d
/0Bw4DMtLCtPMkOTlXR1l4Nkw1WGs/view?usp=drivesdk',
errors: [Object] } ],
response: { responses: [ [Object] ] },
message: 'A failure occurred during this request.' }

将 webViewLink URI 替换为 'traditional' 形式(如 http://www.identifont.com/samples/houseindustries/NeutraText.gif)效果很好。

请注意 https://cloud.google.com/vision/docs/request#providing_the_image 经济特区 "You can provide the image in your request ... As a publicly-accessible HTTP or HTTPS URL"。

对于 vision.detectText(),Drive v3 webViewLink 格式是否应该算作 "publicly-accessible"?

如果不是,应如何修改此格式才能被 vision.detectText() 接受,以支持对 google 驱动器托管的图像进行评估?

虽然这是一个 public 只能访问的 URL,但不幸的是,它是嵌入图像的页面的 URL,而不是 URL图像文件本身。

因此您不能在请求中使用 Google 驱动器 URL。您最简单的选择可能是 Google 云存储...这里有一个网络 UI 可以上传您的图片:

https://console.cloud.google.com/storage/browser

从该页面,您将:

  1. 单击创建存储桶并按照说明进行操作(您可以接受默认值,您只需要创建一个全局唯一的存储桶名称)。
  2. 单击上传文件并select您的图片。
  3. 上传后,select 选中文件旁边的复选框并单击 共享 publicly
  4. 单击 Public link(与文件在同一行)以获取 public URL。

同意 Mike 的观点,我也对 Google App Script to Vision API 进行了一些研究,因为它们都在 Google 保护伞下,所以我错误地假设它们可以 "talk" 彼此(这就是为什么我发现这个 post)。但它无法工作。我相信这就是 Google 愿景 API 的本质。

Mike 的回答只是一点点补充,如果你通过了身份验证(我相信你必须通过这个,因为你需要将文件上传到 Google 存储),那么你可能不会需要将要在您的应用程序中使用的文件指定为 public。