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


Java GoogleAccountCredential.usingOAuth2方法代碼示例

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


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

示例1: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected String doInBackground(thenewpotato.blogg.objects.Comment... params){
    thenewpotato.blogg.objects.Comment mComment = params[0];
    GoogleAccountCredential googleAccountCredential =
            GoogleAccountCredential.usingOAuth2(
                    CommentActivity.this,
                    Collections.singleton(
                            "https://www.googleapis.com/auth/blogger")
            );
    googleAccountCredential.setSelectedAccount(mAccount);
    Blogger service = new Blogger.Builder(HTTP_TRANSPORT, JSON_FACTORY, googleAccountCredential)
            .setApplicationName("Blogger")
            .setHttpRequestInitializer(googleAccountCredential)
            .build();
    try {
        Blogger.Posts.Get get = service.posts().get(mComment.blogId, mComment.postId);
        get.setFields("url");
        Post post = get.execute();
        return post.getUrl();
    }catch (IOException e){
        loge(e.getMessage());
    }
    return null;
}
 
開發者ID:thenewpotato,項目名稱:Blogg,代碼行數:25,代碼來源:CommentActivity.java

示例2: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected BlogList doInBackground(Void... params){
    BlogList result = null;
    try{
        GoogleAccountCredential googleAccountCredential =
                GoogleAccountCredential.usingOAuth2(
                        MainActivity.this,
                        Collections.singleton(
                                "https://www.googleapis.com/auth/blogger")
                );
        googleAccountCredential.setSelectedAccount(mAccount);
        Blogger service = new Blogger.Builder(HTTP_TRANSPORT, JSON_FACTORY, googleAccountCredential)
                .setApplicationName("Blogg")
                .setHttpRequestInitializer(googleAccountCredential)
                .build();
        Blogger.Blogs.ListByUser blogListByUser = service.blogs().listByUser("self");
        result = blogListByUser.execute();
    } catch (IOException e){
        loge("GetListOfBlogTask: IOException, failed!, message= " + e.getMessage());
    }
    return result;
}
 
開發者ID:thenewpotato,項目名稱:Blogg,代碼行數:23,代碼來源:MainActivity.java

示例3: getGoogleTasksService

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
public static Tasks getGoogleTasksService(final Context context, String accountName) {
    final GoogleAccountCredential credential =
            GoogleAccountCredential.usingOAuth2(context, ListManager.TASKS_SCOPES);
    credential.setSelectedAccountName(accountName);
    Tasks googleService =
        new Tasks.Builder(TRANSPORT, JSON_FACTORY, credential)
                 .setApplicationName(DateUtils.getAppName(context))
                 .setHttpRequestInitializer(new HttpRequestInitializer() {
                     @Override
                     public void initialize(HttpRequest httpRequest) {
                         credential.initialize(httpRequest);
                         httpRequest.setConnectTimeout(3 * 1000);  // 3 seconds connect timeout
                         httpRequest.setReadTimeout(3 * 1000);  // 3 seconds read timeout
                     }
                 })
                 .build();
    return googleService;
}
 
開發者ID:danielebufarini,項目名稱:Reminders,代碼行數:19,代碼來源:Reminders.java

示例4: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ensureFetcher();

    credential = GoogleAccountCredential.usingOAuth2(
            getApplicationContext(), Arrays.asList(Utils.SCOPES));
    // set exponential backoff policy
    credential.setBackOff(new ExponentialBackOff());

    if (savedInstanceState != null) {
        mChosenAccountName = savedInstanceState.getString(ACCOUNT_KEY);
    } else {
        loadAccount();
    }

    credential.setSelectedAccountName(mChosenAccountName);

    mEventsListFragment = (EventsListFragment) getFragmentManager()
            .findFragmentById(R.id.list_fragment);
}
 
開發者ID:holtaf,項目名稱:youtube_livestream,代碼行數:25,代碼來源:MainActivity.java

示例5: startUpload

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
public void startUpload(View view) {

        if (isConnected) {
            if (isScannedOnce) {
                if (credential != null) {
                    uploadFileToDrive();
                } else {
                    credential = GoogleAccountCredential.usingOAuth2(this, Arrays.asList(DriveScopes.DRIVE));
                    startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_UPLOAD);
                }

            } else {
                showToast("Must scan before upload");
            }
        }
    }
 
開發者ID:s-papanastasiou,項目名稱:wireless-positioning,代碼行數:17,代碼來源:DetectorActivity.java

示例6: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ensureLoader();

    credential = GoogleAccountCredential.usingOAuth2(
            getApplicationContext(), Arrays.asList(Utils.SCOPES));
    // set exponential backoff policy
    credential.setBackOff(new ExponentialBackOff());

    if (savedInstanceState != null) {
        mChosenAccountName = savedInstanceState.getString(ACCOUNT_KEY);
    } else {
        loadAccount();
    }

    credential.setSelectedAccountName(mChosenAccountName);

    mEventsListFragment = (EventsListFragment) getFragmentManager()
            .findFragmentById(R.id.list_fragment);
}
 
開發者ID:youtube,項目名稱:yt-watchme,代碼行數:25,代碼來源:MainActivity.java

示例7: onCreate

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  
  setContentView(R.layout.activity_main);
  mExchangeCodeEditText = (EditText) findViewById(R.id.editTextExchangeCode);
  mIdTokenEditText = (EditText) findViewById(R.id.editTextIdToken);
  
  // initiate a credential object with drive and plus.login scopes
  // cross identity is only available for tokens retrieved with plus.login
  mCredential = GoogleAccountCredential.usingOAuth2(this, null);
  
  // user needs to select an account, start account picker
  startActivityForResult(
      mCredential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
}
 
開發者ID:googledrive,項目名稱:crossclientoauth2-android,代碼行數:17,代碼來源:MainActivity.java

示例8: getCredentials

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
public static GoogleAccountCredential getCredentials(Context ctx, boolean useDefaultAccount) {
  if (credential == null) {
    List<String> scopes = Arrays.asList(YouTubeScopes.YOUTUBE);

    credential = GoogleAccountCredential.usingOAuth2(ctx.getApplicationContext(), scopes);

    // add account name if we have it
    String accountName = null;

    if (useDefaultAccount)
      accountName = accountName(ctx);

    if (accountName != null)
      credential.setSelectedAccountName(accountName);
  }

  return credential;
}
 
開發者ID:sgehrman,項目名稱:UTubeTV,代碼行數:19,代碼來源:Auth.java

示例9: onHandleIntent

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@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
    }
}
 
開發者ID:sgehrman,項目名稱:youtubeAPI,代碼行數:23,代碼來源:UploadService.java

示例10: 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

示例11: 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

示例12: doInBackground

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Override
protected ArrayList<thenewpotato.blogg.objects.Comment> doInBackground(ArrayList<Comment>... params){
    // comments is only a primitive list containing basic information: blogId, postId, id, and inReplyToId
    comments = params[0];

    GoogleAccountCredential googleAccountCredential =
            GoogleAccountCredential.usingOAuth2(
                    mContext,
                    Collections.singleton(
                            "https://www.googleapis.com/auth/blogger")
            );
    googleAccountCredential.setSelectedAccount(mAccount);
    Blogger service = new Blogger.Builder(HTTP_TRANSPORT, JSON_FACTORY, googleAccountCredential)
            .setApplicationName("Blogger")
            .setHttpRequestInitializer(googleAccountCredential)
            .build();
    try {
        for (int i = 0; i < comments.size(); i++) {
            Comment comment = comments.get(i);
            Blogger.Comments.Get getComment = service.comments().get(comment.blogId, comment.postId, comment.id);
            getComment.setFields("author/displayName,updated,content,author/image/url");
            com.google.api.services.blogger.model.Comment resultComment = getComment.execute();
            Blogger.Posts.Get getPost = service.posts().get(comment.blogId, comment.postId);
            getPost.setFields("title");
            replaceCommentItem(i, resultComment, getPost.execute());
        }
    } catch (IOException e){
        loge(e.getMessage());
    }
    return comments;
}
 
開發者ID:thenewpotato,項目名稱:Blogg,代碼行數:32,代碼來源:GetDetailedCommentsTask.java

示例13: YouTubeSearch

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
public YouTubeSearch(Activity activity, Fragment playlistFragment)
{
    this.activity = activity;
    this.playlistFragment = playlistFragment;
    handler = new Handler();
    credential = GoogleAccountCredential.usingOAuth2(activity.getApplicationContext(),
            Arrays.asList(Auth.SCOPES));

    // set exponential backoff policy
    credential.setBackOff(new ExponentialBackOff());
    appName = activity.getResources().getString(R.string.app_name);
    language = Locale.getDefault().getLanguage();
}
 
開發者ID:teocci,項目名稱:YouTube-In-Background,代碼行數:14,代碼來源:YouTubeSearch.java

示例14: GtasksInvoker

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
@Inject
public GtasksInvoker(@ForApplication Context context, GtasksPreferenceService preferenceService, AccountManager accountManager) {
    this.accountManager = accountManager;
    credential = GoogleAccountCredential.usingOAuth2(context, Collections.singletonList(TasksScopes.TASKS));
    setUserName(preferenceService.getUserName());
    service = new Tasks.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
            .setApplicationName(String.format("Tasks/%s", BuildConfig.VERSION_NAME))
            .build();
}
 
開發者ID:andyCano,項目名稱:TaskApp,代碼行數:10,代碼來源:GtasksInvoker.java

示例15: buildGoogleAccountCredential

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //導入方法依賴的package包/類
/**
 * Build the credential to authorize the installed application to access user's protected data.
 */
private GoogleAccountCredential buildGoogleAccountCredential() throws Exception {
 GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(activity, scopes);
    credential.setBackOff(new ExponentialBackOff());
    credential.setSelectedAccountName(selectedGoogleAccount);
    return credential;
}
 
開發者ID:jayxue,項目名稱:YouTubeUploader,代碼行數:10,代碼來源:YouTubeUploadTask.java


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