use*_*451 5 java android google-oauth
我可以将我的 Android 设备上的一次性使用令牌交换为访问令牌和刷新令牌。我想弄清楚如何使用刷新令牌。
我发现这适用于 HTTPS 请求,但我想知道 Java SDK 中是否有一些地方可以处理刷新?
你不需要\xe2\x80\x99。只需在每次 HTTP 会话之前调用 GoogleAuthUtil.getToken(),GoogleAuthUtil 将确保您获得一个有效的会话,并在必要时刷新。
\n\n编辑:哦,好的,他正在服务器上执行此操作。下面是一些使用刷新令牌的 Java 代码:
\n\n String data = "refresh_token=" + mRefreshToken +\n "&client_id=" + Constants.WEB_CLIENT_ID +\n "&client_secret=" + Constants.WEB_CLIENT_SECRET +\n "&grant_type=refresh_token";\n byte[] body = data.getBytes();\n\n URL url = new URL(Constants.GOOGLE_TOKEN_ENDPOINT);\n conn = (HttpURLConnection) url.openConnection();\n conn.setDoOutput(true);\n conn.setFixedLengthStreamingMode(body.length);\n conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");\n conn.getOutputStream().write(body);\n\n body = XAuth.readStream(conn.getInputStream());\n JSONObject json = new JSONObject(new String(body));\n\n String accessToken = json.optString("access_token");\n if (accessToken == null) {\n throw new Exception("Refresh token yielded no access token");\n }\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
3319 次 |
| 最近记录: |