Android oAuth刷新令牌返回null

Android oAuth刷新令牌返回null,android,oauth,oauth-2.0,google-oauth,Android,Oauth,Oauth 2.0,Google Oauth,我想弄明白这一点已经有一段时间了,似乎我做过的任何事情都做不到 我似乎无法检索刷新令牌,它将显示为空白 public class oaUTH extends AsyncTask<Void, Void, Void> { protected Void doInBackground(Void... unused) { try { JsonFactory jsonFactory = new JacksonFactory();

我想弄明白这一点已经有一段时间了,似乎我做过的任何事情都做不到

我似乎无法检索刷新令牌,它将显示为空白

 public class oaUTH extends AsyncTask<Void, Void, Void>  {



    protected Void doInBackground(Void... unused) {

        try {
            JsonFactory jsonFactory = new JacksonFactory();
            HttpTransport transport = new NetHttpTransport();

            CredentialStore credentialStore = new SharedPreferencesCredentialStore(prefs);
            AccessTokenResponse accessTokenResponse = credentialStore.read();

            GoogleAccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(accessTokenResponse.accessToken,
                                                                                                                            transport,
                                                                                                                            jsonFactory,
                                                                                                                            OAuth2ClientCredentials.CLIENT_ID,
                                                                                                                            OAuth2ClientCredentials.CLIENT_SECRET,
                                                                                                                            accessTokenResponse.refreshToken+"&access_type=offline");       
            final Latitude latitude = new Latitude(transport, accessProtectedResource, jsonFactory);
            latitude.apiKey=OAuth2ClientCredentials.API_KEY;
            Log.i("AGENTPORTAL", "Access Token = " + accessTokenResponse.accessToken + ", Expires in = " + accessTokenResponse.expiresIn + ", Refresh Token = " + accessTokenResponse.refreshToken + ", Scope = " + accessTokenResponse.scope);

            LatitudeCurrentlocationResourceJson currentLocation = latitude.currentLocation.get().execute();
            String locationAsString = convertLocationToString(currentLocation);

            Log.i("TAG", locationAsString);
            //textView.setText(locationAsString);



        } catch (Exception ex) {
            ex.printStackTrace();
            //textView.setText("Error occured : " + ex.getMessage());
            startActivity(new Intent().setClass(getApplicationContext(),OAuthAccessTokenActivity.class));
        }
公共类oaUTH扩展异步任务{
受保护的空位背景(空位…未使用){
试一试{
JsonFactory JsonFactory=新的JacksonFactory();
HttpTransport传输=新的NetHttpTransport();
CredentialStore CredentialStore=新共享的参考CredentialStore(首选);
AccessTokenResponse AccessTokenResponse=credentialStore.read();
GoogleAccessProtectedResource accessProtectedResource=新的GoogleAccessProtectedResource(accessTokenResponse.accessToken,
运输,,
杰森工厂,
OAuth2ClientCredentials.CLIENT_ID,
OAuth2ClientCredentials.CLIENT_SECRET,
accessTokenResponse.refreshToken+“&access_type=offline”);
最终纬度=新纬度(运输、accessProtectedResource、jsonFactory);
latitude.apiKey=OAuth2ClientCredentials.API_键;
Log.i(“AGENTPORTAL”、“Access Token=“+accessTokenResponse.accessToken+”,在=“+accessTokenResponse.expiresIn+”中过期,刷新Token=“+accessTokenResponse.refreshToken+”,范围=“+accessTokenResponse.Scope”);
LatitudeCurrentlocationResourceJson currentLocation=latitude.currentLocation.get().execute();
String locationAsString=convertLocationToString(当前位置);
Log.i(“标签”,位置字符串);
//setText(locationAsString);
}捕获(例外情况除外){
例如printStackTrace();
//textView.setText(“发生错误:+ex.getMessage());
startActivity(new Intent().setClass(getApplicationContext(),OAuthAccessTokenActivity.class));
}
以下是日志:访问令牌=**AHES6ZTeqgwdxjll6Gb4Cf9I0_n5bO_OdgR2OR**WLPCPzJ5xtO5M,到期时间=3599,刷新令牌=,范围=


知道刷新令牌“”在哪里吗?我已经添加了“&access\u type=offline”,但仍然没有运气。非常感谢您的帮助!

我刚刚知道如何获取刷新令牌,我会告诉您我做了什么,以防有人遇到同样的问题

        String authorizationUrl = new GoogleAuthorizationRequestUrl(        
            OAuth2ClientCredentials.CLIENT_ID,
            OAuth2ClientCredentials.REDIRECT_URI,
            OAuth2ClientCredentials.SCOPE).build();
这段代码是启动整个授权过程时首先调用的代码。它缺少的是一些人在此提出的建议,您需要在URL链接中包含“access\u type=offline&approval\u prompt=force

为了让它工作,我只需将authorizationUrl更改为

                    String authorizationUrl = "https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&client_id=" + OAuth2ClientCredentials.CLIENT_ID + "&redirect_uri=" + OAuth2ClientCredentials.REDIRECT_URI + "&response_type=code&scope=" + OAuth2ClientCredentials.SCOPE