在Android中获取Google访问令牌到期时间

时间:2014-12-04 17:26:46

标签: android oauth-2.0 google-plus google-oauth google-login

根据this post,可以使用以下代码获取Google+访问令牌:

AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
            String token = null;

            try {
                token = GoogleAuthUtil.getToken(
                        MainActivity.this,
                        mGoogleApiClient.getAccountName(),
                        "oauth2:" + SCOPES);
            } catch (IOException transientEx) {
                // Network or server error, try later
                Log.e(TAG, transientEx.toString());
            } catch (UserRecoverableAuthException e) {
                // Recover (with e.getIntent())
                Log.e(TAG, e.toString());
                Intent recover = e.getIntent();
                startActivityForResult(recover, REQUEST_CODE_TOKEN_AUTH);
            } catch (GoogleAuthException authEx) {
                // The call is not ever expected to succeed
                // assuming you have already verified that 
                // Google Play services is installed.
                Log.e(TAG, authEx.toString());
            }

            return token;
        }

        @Override
        protected void onPostExecute(String token) {
            Log.i(TAG, "Access token retrieved:" + token);
        }

是否也可以使用GoogleAuthUtilAccountManager获取访问令牌到期日期?或者只有解决方案使用以前的令牌调用到https://accounts.google.com/o/oauth2/auth的HTTPS POST?

0 个答案:

没有答案