Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android GAE中的grant_错误无效代码_Android_Google App Engine_Oauth 2.0 - Fatal编程技术网

android GAE中的grant_错误无效代码

android GAE中的grant_错误无效代码,android,google-app-engine,oauth-2.0,Android,Google App Engine,Oauth 2.0,我目前正在遵循Android GAE应用程序中提供的跨客户端验证说明,因此我的用户可以代表他们向Python后端离线访问G+API。这些文档也指导了我,这正是我遇到的问题所在。我已成功获取授权代码并将其发送到后端,但当后端尝试将该代码交换为访问和刷新令牌时,我会得到“错误:无效授予”和“错误描述:无效代码”。举例来说,当我将代码和其他需要的信息复制到curl中时,输出如下: curl -d "code=4/uG6moqbHvs9hgfG1HmEfT39zT1j0.Un-H_36OXGUWmmS0

我目前正在遵循Android GAE应用程序中提供的跨客户端验证说明,因此我的用户可以代表他们向Python后端离线访问G+API。这些文档也指导了我,这正是我遇到的问题所在。我已成功获取授权代码并将其发送到后端,但当后端尝试将该代码交换为访问和刷新令牌时,我会得到“错误:无效授予”和“错误描述:无效代码”。举例来说,当我将代码和其他需要的信息复制到curl中时,输出如下:

curl -d "code=4/uG6moqbHvs9hgfG1HmEfT39zT1j0.Un-H_36OXGUWmmS0T3UFEsMwQpwOhwI&client_secret={MY_SECRET}&client_id={MY_WEB_CLIENT_ID}&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token -v
* Adding handle: conn: 0x7fc359803a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fc359803a00) send_pipe: 1, recv_pipe: 0
* About to connect() to accounts.google.com port 443 (#0)
*   Trying 74.125.28.84...
* Connected to accounts.google.com (74.125.28.84) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_RC4_128_SHA
* Server certificate: accounts.google.com
* Server certificate: Google Internet Authority G2
* Server certificate: GeoTrust Global CA
* Server certificate: Equifax Secure Certificate Authority
> POST /o/oauth2/token HTTP/1.1
> User-Agent: curl/7.30.0
> Host: accounts.google.com
> Accept: */*
> Content-Length: 219
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 219 out of 219 bytes
< HTTP/1.1 400 Bad Request
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: Fri, 01 Jan 1990 00:00:00 GMT
< Date: Sun, 12 Jan 2014 16:38:42 GMT
< Content-Type: application/json
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
* Server GSE is not blacklisted
< Server: GSE
< Alternate-Protocol: 443:quic
< Transfer-Encoding: chunked
< 
{
  "error" : "invalid_grant",
  "error_description" : "Invalid code.[Email: \n\nToken Record:\nToken: \"4/uG6moqbHvs9hgfG1HmEfT39zT1j0.Un-H_36OXGUWmmS0T3UFEsMwQpwOhwI\"\nIssueDomain: \"206701529154-7d35h3g4a22aef8d78p6up1cdiq3pl4d.apps.googleusercontent.com\"\nIssueTimeSec: 1389544361\nExpirationTime: 1389544961\nTokenUsage: 3\nScope: \"https://www.googleapis.com/auth/plus.login\"\nScope: \"https://www.googleapis.com/auth/userinfo.profile\"\nScope: \"https://www.googleapis.com/auth/userinfo.email\"\nScope: \"https://www.googleapis.com/auth/plus.moments.write\"\nScope: \"https://www.googleapis.com/auth/plus.me\"\nScope: \"https://www.googleapis.com/auth/plus.profile.agerange.read\"\nScope: \"https://www.googleapis.com/auth/plus.profile.language.read\"\nScope: \"https://www.googleapis.com/auth/plus.circles.members.read\"\nServiceInfo {\n  ServiceId: 226\n  Info <\n    [security_lso_auth_oauth2.EarlyIssuedTokenProto] <\n      auto_approved: false\n      access_token: \"ya29.1.AADtN_UyJ2wiWB7lh7btUiCwUyHzix_DrubjdSsTxA6drG-ZccPWaeZJa31sebPnRCHiFw\"\n      refresh_token: \"1/ImSjHYLkFcBOwsCezBg2dKpcqko9by3nTIh_k33ZMds\"\n    >\n  >\n}\nRevoked: true\nAuthorizedBy: 0x866419b291\nOAuthCallbackUrl: \"urn:accounts.google.com:api_auth:programmatic:virtual_redirect_uri\"\nOfflineAccess: true\nRevokeOnPasswordChange: true\nClientManagedRevocation: false\nInBundle: true\n]"
* Connection #0 to host accounts.google.com left intact
}% 
curl-d“code=4/uG6moqbHvs9hgfG1HmEfT39zT1j0.Un-H_36OXGUWmmS0T3UFEsMwQpwOhwI&client_secret={MY_secret}和client_id={MY_WEB_client_id}和grant_type=authorization_code”https://accounts.google.com/o/oauth2/token -五
*添加句柄:conn:0x7fc359803a00
*正在添加句柄:发送:0
*正在添加句柄:recv:0
*卷曲度加把手尺寸线:长度:1
*-Conn 0(0x7fc359803a00)发送管道:1,接收管道:0
*即将连接()到accounts.google.com端口443(#0)
*正在尝试74.125.28.84。。。
*已连接到accounts.google.com(74.125.28.84)端口443(#0)
*使用TLS_ECDHE_RSA_与_RC4_128_SHA的TLS 1.2连接
*服务器证书:accounts.google.com
*服务器证书:Google Internet Authority G2
*服务器证书:GeoTrust全局CA
*服务器证书:Equifax安全证书颁发机构
>POST/o/oauth2/token HTTP/1.1
>用户代理:curl/7.30.0
>主持人:accounts.google.com
>接受:*/*
>内容长度:219
>内容类型:application/x-www-form-urlencoded
> 
*上传已完全发送:219字节中的219字节

我在理解此错误消息以确定授权代码无效的原因时遇到了很多问题。我确实注意到,在资源管理器日志中,所有日志在过去的一个小时内都有时间戳(因此,当我在上午11点发布日志时,它会以上午10点的时间戳显示在资源管理器中)。时区差异是否会导致oauth2服务器认为我提交的授权代码太旧?我已尝试更改系统时间以匹配日志时间,但没有结果。有人知道是什么原因导致我的授权代码无效吗?我已在上下搜索了数小时。

发布后不久在回答这个问题时,我自己找到了答案。如果其他人遇到同样的问题,我会将答案发布到这里。我注意到,在中出现了类似的错误,原因是开发人员需要在10分钟内多次请求刷新/访问令牌(这是一次性授权代码的过期时间)。再次检查我的浏览器日志,我发现我的android代码中有一个bug,导致我的跨客户端验证代码快速连续运行两次,而不是像预期的那样只运行一次。第一次运行时,刷新和访问令牌被正确返回。第二次,生成错误


回想起来,错误消息中的“reversed=True”部分应该已经为我指明了答案。

但是如果在一个场景中,我想快速连续地获取令牌呢?我已经使用GoogleAuthUtil.invalidateToken(此代码)手动使生成的令牌无效。然后我也会得到相同的错误。