直到昨天,Google Natural Language 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 的调用会响应对关键限制的更改。
从演示页面进行的调用也会显示权限错误消息。但是,来自API 资源管理器的调用确实有效。
编辑:
该错误也发生在产品网页上的演示中。跟踪 Charles 中的错误会显示相同的“权限被拒绝”响应返回到网页:
编辑:
下面是从演示页面捕获的 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"
}
}