@Override public UserRecoverableAuthException getCause() { return (UserRecoverableAuthException) super.getCause(); }
@Override public GooglePlayServicesAvailabilityException getCause() { return (GooglePlayServicesAvailabilityException) super.getCause(); }
@Override public void intercept(HttpRequest request) throws IOException { try { token = getToken(); request.getHeaders().setAuthorization("Bearer " + token); } catch (GooglePlayServicesAvailabilityException e) { throw new GooglePlayServicesAvailabilityIOException(e); } catch (UserRecoverableAuthException e) { throw new UserRecoverableAuthIOException(e); } catch (GoogleAuthException e) { throw new GoogleAuthIOException(e); } }
@Override protected void onHandleIntent(Intent intent) { Uri fileUri = intent.getData(); String chosenAccountName = intent.getStringExtra(MainActivity.ACCOUNT_KEY); credential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Lists.newArrayList(Auth.SCOPES)); credential.setSelectedAccountName(chosenAccountName); credential.setBackOff(new ExponentialBackOff()); String appName = getResources().getString(R.string.app_name); final YouTube youtube = new YouTube.Builder(transport, jsonFactory, credential).setApplicationName( appName).build(); try { tryUploadAndShowSelectableNotification(fileUri, youtube); } catch (InterruptedException e) { // ignore } }
public void updateCredential(SharedPreferences prefs){ credential = GoogleAccountCredential.usingOAuth2( getApplicationContext(), Arrays.asList(GMConstants.SCOPES)) .setBackOff(new ExponentialBackOff()) .setSelectedAccountName(prefs.getString(GMConstants.PREF_ACCOUNT_NAME, null)); if(credential != null && credential.getSelectedAccount() != null) { gmailService = new com.google.api.services.gmail.Gmail.Builder( transport, jsonFactory, credential) .setApplicationName("Shortyz") .build(); } else { gmailService = null; } }
private void chooseAccount() { startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER); }
if (accountName != null) { mChosenAccountName = accountName; credential.setSelectedAccountName(accountName); saveAccount();
@Override public void run() { try { application.getCredential().getToken(); } catch (final UserRecoverableAuthException e) { runOnUiThread(new Runnable() { @Override public void run() { startActivityForResult(e.getIntent(), GMConstants.REQUEST_AUTHORIZATION); } }); } catch (Exception e) { LOGGER.log(Level.SEVERE, "WTF", e); } } };
/** * Sets the audience scope to use with Google Cloud Endpoints. * * @param context context * @param audience audience * @return new instance */ public static GoogleAccountCredential usingAudience(Context context, String audience) { Preconditions.checkArgument(audience.length() != 0); return new GoogleAccountCredential(context, "audience:" + audience); }
private static void requestAuth(Context context, UserRecoverableAuthIOException userRecoverableException) { LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context); Intent authIntent = userRecoverableException.getIntent(); Intent runReqAuthIntent = new Intent(MainActivity.REQUEST_AUTHORIZATION_INTENT); runReqAuthIntent.putExtra(MainActivity.REQUEST_AUTHORIZATION_INTENT_PARAM, authIntent); manager.sendBroadcast(runReqAuthIntent); Log.d(TAG, String.format("Sent broadcast %s", MainActivity.REQUEST_AUTHORIZATION_INTENT)); }
/** * Returns the error code to use with * {@link GooglePlayServicesUtil#getErrorDialog(int, Activity, int)}. */ public final int getConnectionStatusCode() { return getCause().getConnectionStatusCode(); } }
private void haveGooglePlayServices() { // check if there is already an account selected if (credential.getSelectedAccountName() == null) { // ask user to choose account chooseAccount(); } }
/** * @param wrapped wrapped {@link GoogleAuthException} * @since 1.21.0 */ public GoogleAuthIOException(GoogleAuthException wrapped) { initCause(Preconditions.checkNotNull(wrapped)); }
@Override public void initialize(HttpRequest request) { RequestHandler handler = new RequestHandler(); request.setInterceptor(handler); request.setUnsuccessfulResponseHandler(handler); }
@Override protected void onCreate(Bundle savedInstanceState) { getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); mUploadsListFragment = new UploadsListFragment(getApplicationContext()); // Check to see if the proper keys and playlist IDs have been set up if (!isCorrectlyConfigured()) { setContentView(R.layout.developer_setup_required); showMissingConfigurations(); } else { setContentView(R.layout.activity_main); ensureLoader(); credential = GoogleAccountCredential.usingOAuth2( getApplicationContext(), Arrays.asList(Auth.SCOPES)); // set exponential backoff policy credential.setBackOff(new ExponentialBackOff()); if (savedInstanceState != null) { mChosenAccountName = savedInstanceState.getString(ACCOUNT_KEY); } else { loadAccount(); } credential.setSelectedAccountName(mChosenAccountName); mUploadsListFragment = (UploadsListFragment) getFragmentManager() .findFragmentById(R.id.list_fragment); } }
/** * Starts an activity in Google Play Services so the user can pick an * account. */ public void chooseAccount() { startActivityForResult( ((ShortyzApplication) getApplication()).getCredential().newChooseAccountIntent(), GMConstants.REQUEST_ACCOUNT_PICKER); }
if (accountName != null) { final ShortyzApplication application = ((ShortyzApplication) getApplication()); application.getCredential().setSelectedAccountName(accountName); SharedPreferences settings = application.getSettings(); settings.edit()
/** * Returns the {@link Intent} that when supplied to * {@link Activity#startActivityForResult(Intent, int)} will allow user intervention. */ public final Intent getIntent() { return getCause().getIntent(); } }
/** * Constructs a new instance using OAuth 2.0 scopes. * * @param context context * @param scopes non empty OAuth 2.0 scope list * @return new instance * * @since 1.15 */ public static GoogleAccountCredential usingOAuth2(Context context, Collection<String> scopes) { Preconditions.checkArgument(scopes != null && scopes.iterator().hasNext()); String scopesStr = "oauth2: " + Joiner.on(' ').join(scopes); return new GoogleAccountCredential(context, scopesStr); }
@Override protected Void doInBackground(Void... voids) { YouTube youtube = new YouTube.Builder(transport, jsonFactory, credential).setApplicationName(Constants.APP_NAME) .build(); try { youtube.videos().update("snippet", updateVideo).execute(); } catch (UserRecoverableAuthIOException e) { startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) { Log.e(TAG, e.getMessage()); } return null; }