List of usage examples for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential setBackOff
public GoogleAccountCredential setBackOff(BackOff backOff)
From source file:com.jefftharris.passwdsafe.sync.gdrive.GDriveProvider.java
License:Open Source License
/** * Retrieve a authorized service object to send requests to the Google * Drive API. On failure to retrieve an access token, a notification is * sent to the user requesting that authorization be granted for the * {@code https://www.googleapis.com/auth/drive} scope. * * @return An authorized service object and its auth token. */// w w w .jav a 2 s . co m private static Pair<Drive, String> getDriveService(Account acct, Context ctx) { Drive drive = null; String token = null; try { GoogleAccountCredential credential = getAcctCredential(ctx); credential.setBackOff(new ExponentialBackOff()); credential.setSelectedAccountName(acct.name); token = GoogleAuthUtil.getTokenWithNotification(ctx, acct, credential.getScope(), null, PasswdSafeContract.AUTHORITY, null); Drive.Builder builder = new Drive.Builder(AndroidHttp.newCompatibleTransport(), JacksonFactory.getDefaultInstance(), credential); builder.setApplicationName(ctx.getString(R.string.app_name)); drive = builder.build(); } catch (UserRecoverableNotifiedException e) { // User notified PasswdSafeUtil.dbginfo(TAG, e, "User notified auth exception"); try { GoogleAuthUtil.clearToken(ctx, null); } catch (Exception ioe) { Log.e(TAG, "getDriveService clear failure", e); } } catch (GoogleAuthException e) { // Unrecoverable Log.e(TAG, "Unrecoverable auth exception", e); } catch (IOException e) { // Transient PasswdSafeUtil.dbginfo(TAG, e, "Transient error"); } catch (Exception e) { Log.e(TAG, "Token exception", e); } return new Pair<>(drive, token); }