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


Java GoogleAccountCredential.getToken方法代碼示例

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


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

示例1: create

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
public static Drive create(Context context, String googleDriveAccount) throws IOException, GoogleAuthException, ImportExportException {
    if (googleDriveAccount == null) {
        throw new ImportExportException(R.string.google_drive_account_required);
    }
    try {
        List<String> scope = new ArrayList<String>();
        scope.add(DriveScopes.DRIVE_FILE);
        if (MyPreferences.isGoogleDriveFullReadonly(context)) {
            scope.add(DriveScopes.DRIVE_READONLY);
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
        credential.setSelectedAccountName(googleDriveAccount);
        credential.getToken();
        return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
    } catch (UserRecoverableAuthException e) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent authorizationIntent = e.getIntent();
        authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
                Intent.FLAG_FROM_BACKGROUND);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                authorizationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.ic_dialog_alert)
                .setTicker(context.getString(R.string.google_drive_permission_requested))
                .setContentTitle(context.getString(R.string.google_drive_permission_requested))
                .setContentText(context.getString(R.string.google_drive_permission_requested_for_account, googleDriveAccount))
                .setContentIntent(pendingIntent).setAutoCancel(true).build();
        notificationManager.notify(0, notification);
        throw new ImportExportException(R.string.google_drive_permission_required);
    }
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:33,代碼來源:GoogleDriveClient.java

示例2: create

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
public static Drive create(Context context) throws IOException, GoogleAuthException, ImportExportException {
    String googleDriveAccount = MyPreferences.getGoogleDriveAccount(context);
    if (googleDriveAccount == null) {
        throw new ImportExportException(R.string.google_drive_account_required);
    }
    try {
        List<String> scope = new ArrayList<String>();
        scope.add(DriveScopes.DRIVE_FILE);
        if (MyPreferences.isGoogleDriveFullReadonly(context)) {
            scope.add(DriveScopes.DRIVE_READONLY);
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
        credential.setSelectedAccountName(googleDriveAccount);
        credential.getToken();
        return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
    } catch (UserRecoverableAuthException e) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent authorizationIntent = e.getIntent();
        authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
                Intent.FLAG_FROM_BACKGROUND);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                authorizationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.ic_dialog_alert)
                .setTicker(context.getString(R.string.google_drive_permission_requested))
                .setContentTitle(context.getString(R.string.google_drive_permission_requested))
                .setContentText(context.getString(R.string.google_drive_permission_requested_for_account, googleDriveAccount))
                .setContentIntent(pendingIntent).setAutoCancel(true).build();
        notificationManager.notify(0, notification);
        throw new ImportExportException(R.string.google_drive_permission_required);
    }
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:34,代碼來源:GoogleDrivePictureClient.java

示例3: clearToken

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的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

示例4: getGoogleAccountCredential

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Gets the google account credential.
 * 
 * @param context the context
 * @param accountName the account name
 * @param scope the scope
 */
public static GoogleAccountCredential getGoogleAccountCredential(
    Context context, String accountName, String scope) throws IOException, GoogleAuthException {
  GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
  credential.setSelectedAccountName(accountName);
  credential.getToken();
  return credential;
}
 
開發者ID:Plonk42,項目名稱:mytracks,代碼行數:15,代碼來源:SendToGoogleUtils.java

示例5: create

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
public static Drive create(Context context, String googleDriveAccount) throws IOException, GoogleAuthException, ImportExportException {
    if (googleDriveAccount == null) {
        throw new ImportExportException(R.string.google_drive_account_select_error);
    }
    try {
        List<String> scope = new ArrayList<String>();
        scope.add(DriveScopes.DRIVE_FILE);
        if (MyPreferences.isGoogleDriveFullReadonly(context)) {
            scope.add(DriveScopes.DRIVE_READONLY);
        }
        GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
        credential.setSelectedAccountName(googleDriveAccount);
        credential.getToken();
        return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
    } catch (UserRecoverableAuthException e) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent authorizationIntent = e.getIntent();
        authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
                Intent.FLAG_FROM_BACKGROUND);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                authorizationIntent, 0);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(android.R.drawable.ic_dialog_alert)
                .setTicker(context.getString(R.string.google_drive_permission_requested))
                .setContentTitle(context.getString(R.string.google_drive_permission_requested))
                .setContentText(context.getString(R.string.google_drive_permission_requested_for_account) +" " + googleDriveAccount)
                .setContentIntent(pendingIntent).setAutoCancel(true).build();
        notificationManager.notify(0, notification);
        throw new ImportExportException(R.string.google_drive_permission_required);
    }
}
 
開發者ID:emmanuel-florent,項目名稱:flowzr-android-black,代碼行數:33,代碼來源:GoogleDriveClient.java

示例6: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected Boolean doInBackground(String... emailAccounts) {
  Log.i(LOG_TAG, "Background task started.");

  if (!AppConstants.checkGooglePlayServicesAvailable(MainActivity.this)) {
    return false;
  }

  String emailAccount = emailAccounts[0];
  // Ensure only one task is running at a time.
  mAuthTask = this;

  // Ensure an email was selected.
  if (Strings.isNullOrEmpty(emailAccount)) {
    publishProgress(R.string.toast_no_google_account_selected);
    // Failure.
    return false;
  }

  if (DEBUG) {
    Log.d(LOG_TAG, "Attempting to get AuthToken for account: " + mEmailAccount);
  }

  try {
    // If the application has the appropriate access then a token will be retrieved, otherwise
    // an error will be thrown.
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(
        MainActivity.this, AppConstants.AUDIENCE);
    credential.setSelectedAccountName(emailAccount);

    String accessToken = credential.getToken();

    if (DEBUG) {
      Log.d(LOG_TAG, "AccessToken retrieved");
    }

    // Success.
    return true;
  } catch (GoogleAuthException unrecoverableException) {
    Log.e(LOG_TAG, "Exception checking OAuth2 authentication.", unrecoverableException);
    publishProgress(R.string.toast_exception_checking_authorization);
    // Failure.
    return false;
  } catch (IOException ioException) {
    Log.e(LOG_TAG, "Exception checking OAuth2 authentication.", ioException);
    publishProgress(R.string.toast_exception_checking_authorization);
    // Failure or cancel request.
    return false;
  }
}
 
開發者ID:googlearchive,項目名稱:appengine-endpoints-helloendpoints-android,代碼行數:51,代碼來源:MainActivity.java

示例7: getToken

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Gets the OAuth2 token.
 * 
 * @param context the context
 * @param accountName the account name
 * @param scope the scope
 */
public static String getToken(Context context, String accountName, String scope)
    throws IOException, GoogleAuthException {
  GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
  credential.setSelectedAccountName(accountName);
  return credential.getToken();
}
 
開發者ID:Plonk42,項目名稱:mytracks,代碼行數:14,代碼來源:SendToGoogleUtils.java


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