谷歌自然语言API一直在我的iOS应用程序中工作,直到昨天。从今天早上开始,API开始返回“权限被拒绝”的错误。例如:
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}请求示例:
POST /v1/documents:analyzeEntities?key=..... HTTP/1.1
Host: language.googleapis.com
Content-Type: application/json
Connection: keep-alive
X-Ios-Bundle-Identifier: .....
Accept: */*
Accept-Language: en-us
Content-Length: 291
Accept-Encoding: gzip, deflate
User-Agent: CardScanner/1 CFNetwork/808.2.16 Darwin/15.6.0
{"encodingType":"UTF8","document":{"type":"PLAIN_TEXT","content":"....."}}账号开通计费(余额为0美元)。该账户还有36天的试用期。
该键与Google Cloud Platform API仪表板中的值匹配。我还尝试了重新生成密钥,并在应用程序中使用新密钥。
我还尝试为iOS设备启用关键限制,并在应用程序捆绑包标识符中包含"X-Ios- bundle - identifier“标头。
该应用程序还使用了Google Vision API,运行起来没有任何问题。对Vision API的调用会响应对关键限制的更改。
从demo page进行的调用也会显示权限错误消息。但是,来自API explorer的调用确实可以工作。
编辑:
demo on the product web page上也出现错误。跟踪Charles中的错误,将向网页返回相同的"permission denied“响应:

编辑:
下面是从演示页面捕获的HTTP请求和响应的示例。请求和产生的错误与我的应用程序几乎相同,只是演示程序似乎使用的是http 2,而我的应用程序使用的是http 1。
HTTP请求:
:method: POST
:authority: language.googleapis.com
:scheme: https
:path: /v1/documents:analyzeEntities?key=.....
content-length: 250
origin: https://cloud.google.com
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
content-type: text/plain;charset=UTF-8
accept: */*
referer: https://cloud.google.com/natural-language/
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.8
{"document":{"type":"PLAIN_TEXT","content":"Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones."},"encodingType":"UTF16"}HTTP响应:
:status: 403
vary: Origin
vary: X-Origin
vary: Referer
content-type: application/json; charset=UTF-8
content-encoding: gzip
date: Sun, 26 Feb 2017 14:52:24 GMT
server: ESF
cache-control: private
content-length: 128
x-xss-protection: 1; mode=block
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
access-control-allow-origin: https://cloud.google.com
access-control-expose-headers: content-encoding,date,server,content-length
alt-svc: quic=":443"; ma=2592000; v="35,34"
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}发布于 2017-02-28 15:00:04
我们意识到了这个问题,现在应该解决这个问题。如果您仍然看到同样的问题,请让我们知道。
发布于 2017-02-27 20:42:37
我也经历过同样的行为,我相信这是谷歌的一个未经记录的改变。
我现在只能通过OAuth进行调用,尽管文档表明一个API键就足够了。直到最近,还可以仅使用API密钥进行调用,并且在密钥上没有配置任何限制。
我的“答案”是在documentation page上提供反馈,抱怨文档与行为不匹配。我认为页面上的措辞最近可能发生了变化,但它仍然表明API密钥应该用于测试目的。
发布于 2017-02-27 22:50:10
Google Cloud Vision API演示页面中的"TRY NATURAL LANGUAGE API“按钮也不起作用!看起来像是个bug,希望他们能尽快修复它。

https://stackoverflow.com/questions/42431787
复制相似问题