本文整理匯總了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();
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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");
}
}
示例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;
}
示例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;
}