[英]How to get refresh token for google plus in android?
I am using following code to get the access token for google plus. 我使用以下代码来获取google plus的访问令牌。 Is there a way to get the refresh token so that I can access the google API offline from the web server.
有没有办法获取刷新令牌,以便我可以从Web服务器脱机访问谷歌API。
String accountName = params[0];
String scopes = "oauth2:profile email";
String token = null;
try {
token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, scopes);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
} catch (UserRecoverableAuthException e) {
startActivityForResult(e.getIntent(), REQ_SIGN_IN_REQUIRED);
} catch (GoogleAuthException e) {
Log.e(TAG, e.getMessage());
}
This link very clearly explains the api you need to hit to get token and referesh token for your server side polling. 此链接非常清楚地解释了您需要点击以获取服务器端轮询的令牌和referesh令牌的API。
you would receive a response like so. 你会收到这样的回复。
{
"access_token" : "ya29.AHES6ZSuY8f6WFLswSv0HELP2J4cCvFSj-8GiZM0Pr6cgXU",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/551G1yXUqgkDGnkfFk6ZbjMLMDIMxo3JFc8lY8CAR-Q"
}
you would do well to read this guide when playing around with tokens in cross platform scenario. 在跨平台场景中使用令牌时,您最好阅读本指南 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.