當前位置: 首頁>>代碼示例>>Java>>正文


Java GoogleAuthUtil.clearToken方法代碼示例

本文整理匯總了Java中com.google.android.gms.auth.GoogleAuthUtil.clearToken方法的典型用法代碼示例。如果您正苦於以下問題:Java GoogleAuthUtil.clearToken方法的具體用法?Java GoogleAuthUtil.clearToken怎麽用?Java GoogleAuthUtil.clearToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.android.gms.auth.GoogleAuthUtil的用法示例。


在下文中一共展示了GoogleAuthUtil.clearToken方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: DriveSyncService

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
public DriveSyncService() throws UserRecoverableAuthException {
    super(SyncService.GoogleDrive);

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

        String token = GoogleAuthUtil.getToken(GlobalApplication.getAppContext(), Settings.getEmail(), "oauth2:" + DriveScopes.DRIVE_APPDATA);

        if (SettingsUtil.shouldRefreshGDriveToken()) {
            GoogleAuthUtil.clearToken(GlobalApplication.getAppContext(), token);
            token = GoogleAuthUtil.getToken(GlobalApplication.getAppContext(), Settings.getEmail(), "oauth2:" + DriveScopes.DRIVE_APPDATA);
            SettingsUtil.refreshGDriveToken();
        }

        if (BuildConfig.DEBUG)
            LogUtil.log(getClass().getSimpleName(), "Access Token: " + token);

        GoogleCredential credential = new GoogleCredential().setAccessToken(token);
        service = new Drive.Builder(httpTransport, jsonFactory, credential).setApplicationName("Narrate").build();

    } catch (UserRecoverableAuthException ue) {
        throw ue;
    } catch (Exception e) {
        LogUtil.log(getClass().getSimpleName(), "Exception in creation: " + e);
        if (!BuildConfig.DEBUG) Crashlytics.logException(e);
    }

    if (CLEAR_FOLDER_CONTENTS) {
        deleteEverything();
    }
}
 
開發者ID:timothymiko,項目名稱:narrate-android,代碼行數:33,代碼來源:DriveSyncService.java

示例2: clearToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
public void clearToken(GoogleAccountCredential credential) throws IOException {
    try {
        String token = credential.getToken();
        Timber.d("Invalidating %s", token);
        GoogleAuthUtil.clearToken(context, token);
        GoogleAuthUtil.getTokenWithNotification(context, credential.getSelectedAccount(), "oauth2:" + TasksScopes.TASKS, null);
    } catch (GoogleAuthException e) {
        Timber.e(e, e.getMessage());
        throw new IOException(e);
    }
}
 
開發者ID:andyCano,項目名稱:TaskApp,代碼行數:12,代碼來源:AccountManager.java

示例3: fetchToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
/**
 * Gets an authentication token from Google and handles any
 * GoogleAuthException that may occur.
 */
protected String fetchToken() throws IOException {
    String accessToken;
    try {
        accessToken = GoogleAuthUtil.getToken(mActivity, mAccount, mScope);
        GoogleAuthUtil.clearToken (mActivity, accessToken); // used to remove stale tokens.
        accessToken = GoogleAuthUtil.getToken(mActivity, mAccount, mScope);
        return accessToken;
    } catch (UserRecoverableAuthException userRecoverableException) {
        mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
    } catch (GoogleAuthException fatalException) {
        fatalException.printStackTrace();
    }
    return null;
}
 
開發者ID:Truiton,項目名稱:CloudVisionAPI,代碼行數:19,代碼來源:GetTokenTask.java

示例4: retrieveAuthToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
public String retrieveAuthToken(Account account)
        throws GoogleAuthException, IOException {

    String token = GoogleAuthUtil.getToken(mContext, account, SCOPE);
    // Token needs to be clear so we make sure next time we get a brand new one. Otherwise this
    // may return a token that has already been used by the API and because it's a one time
    // token it won't work.
    GoogleAuthUtil.clearToken(mContext, token);
    return token;
}
 
開發者ID:ribot,項目名稱:ribot-app-android,代碼行數:11,代碼來源:GoogleAuthHelper.java

示例5: clearToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
public void clearToken() {
	if (cachedToken == null) return;
	try {
		GoogleAuthUtil.clearToken(context, cachedToken);
		cachedToken = null;
	} catch (Exception e) {
		// is recovery even possible when trying to clear a local cache??
		Timber.e(e, "failed to clear token");
	}
}
 
開發者ID:jvalue,項目名稱:hochwasser-app,代碼行數:11,代碼來源:LoginManager.java

示例6: handleException

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
/**
 * Handle the exception during the refresh.
 * @param e the exception.
 * @return true if the exception is fatal, otherwise false
 */
private boolean handleException(final Exception e, boolean retry){
    e.printStackTrace();
    if (e instanceof GoogleAuthException) {
        showToast(R.string.auth_error);
        mListener.doAuthInActivity();
    } else if (e instanceof IOException) {
        showToast(R.string.network_error);
    } else if (e instanceof RetrofitError) {
        if (((RetrofitError) e).getResponse() == null){
            handleException(new IOException());
        }
        else if (((RetrofitError) e).getResponse().getStatus() == 401) {
            try {
                GoogleAuthUtil.clearToken(getActivity().getApplicationContext(), token);
                // if this is the retry, call the auth activity.
                if (retry){
                    showToast(R.string.auth_error);
                    mListener.doAuthInActivity();
                }
                return false;
            } catch (Exception e1) {
                handleException(e1);
            }
        }
    }
    return true;
}
 
開發者ID:GhostFlying,項目名稱:PortalWaitingList,代碼行數:33,代碼來源:PortalListFragment.java

示例7: invalidateToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
public static boolean invalidateToken(String token) throws IOException, GoogleAuthException {
    GoogleAuthUtil.clearToken(GlobalApplication.getAppContext(), token);
    return true;
}
 
開發者ID:timothymiko,項目名稱:narrate-android,代碼行數:5,代碼來源:GoogleAccountsService.java


注:本文中的com.google.android.gms.auth.GoogleAuthUtil.clearToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。