【问题标题】:Android oAuth Refresh Token returns nullAndroid oAuth 刷新令牌返回 null
【发布时间】:2013-05-10 14:08:29
【问题描述】:

我一直在尝试解决这个问题,但似乎无法接受我尝试过的任何事情。

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

 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));
        }

这里是日志:Access Token = **AHES6ZTeqgwdxjll6Gb4Cf9I0_n5bO_OdgR2OR**WLPCPzJ5xtO5M, Expires in = 3599, Refresh Token = , Scope =

知道刷新令牌=“”在哪里吗?我添加了“&access_type=offline”,但仍然没有运气。非常感谢任何帮助!

【问题讨论】:

    标签: android oauth oauth-2.0 google-oauth


    【解决方案1】:

    我刚刚想出了如何获取刷新令牌,我会告诉你我做了什么,以防万一有人遇到同样的问题......

            String authorizationUrl = new GoogleAuthorizationRequestUrl(        
                OAuth2ClientCredentials.CLIENT_ID,
                OAuth2ClientCredentials.REDIRECT_URI,
                OAuth2ClientCredentials.SCOPE).build();
    

    那段代码首先被调用来启动整个授权过程。其中缺少的是这里的几个人建议的内容,您需要在 URL 链接中包含“access_type=offline&approval_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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-09
      • 2021-11-21
      • 2017-11-21
      • 2016-06-01
      • 2020-05-05
      • 2016-01-05
      • 2017-11-20
      • 2016-03-31
      相关资源
      最近更新 更多