谷歌自然語言API直到昨天一直在我的iOS應用程序中工作。截至今天早上,API開始返回「權限被拒絕」錯誤。 E.g:Google自然語言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雲端平臺API儀表板中的值。我也嘗試重新生成密鑰,並在應用中使用新密鑰。
我還試圖使IOS設備密鑰的限制,並且包括與所述應用程序軟件包標識符的「X-IOS束標識符」報頭。
該應用程序還使用Google Vision API,其工作沒有問題。對Vision API的調用會響應對關鍵限制的更改。從demo page製成
電話也顯示權限錯誤消息。然而,來自API explorer的呼叫確實有效。
編輯:
錯誤也發生在demo on the product web page。跟蹤在查爾斯錯誤顯示了同樣的「權限被拒絕」響應返回給Web頁:
編輯:
下面是從演示頁捕捉到的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"
}
}
這似乎是一個合理的結論。您是否可以使用網頁/ iOS應用中的OAuth訪問API?據我瞭解,OAuth旨在從後端服務器使用,因爲它需要包括一個超級祕密私鑰(或沿着這些線)。 –
在進一步調查中,可以在沒有超級機密信息的情況下使用OAuth。 AppAuth庫看起來很有用:https://openid.github.io/AppAuth-iOS/ –
根據來自@Apoorv Saxena的評論,現在正在工作 – sahmeepee