我正在尝试使用 Google Vision API。我正在关注 getting started guide :
- 我已启用 Cloud Vision API
- 我已启用计费
- 我已经设置了 API key
- 根据我的图像制作 base64 编码数据
制作带有设置的 JSON 文件:
{ "requests":[ { "image":{ "content":"my base64-encoded data" }, "features":[ { "type":"LABEL_DETECTION", "maxResults":5 } ] } ] }
使用
curl
发送请求:$ curl -v -k -s -H "Content-Type: application/json" https://vision.googleapis.com/v1/images:annotate?key=my_browser_key --data-binary @path_to_file.json
之后我得到了回复:
{
"error": {
"code": 403,
"message": "Requests from referer \u003cempty\u003e are blocked.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developer console API key",
"url": "https://console.developers.google.com/project/***********/apiui/credential"
}
]
}
]
}
}
\u003cempty\u003e 表示
有什么想法吗?有人有同样的问题吗?
最佳答案
您是否在该页面上显示的“接受来自这些 HTTP 引荐来源网址的请求”框中指定了有效引荐来源网址列表?如果你这样做了,你可能必须指定其中之一:
curl --referer https://yourwebsite.com/ ...
或者如果您不需要它,只需禁用 referer 检查。
关于google-cloud-vision - Google Vision API 返回 PERMISSION_DENIED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35672845/