当前位置: 首页>>代码示例>>Java>>正文


Java GoogleAccountCredential类代码示例

本文整理汇总了Java中com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential的典型用法代码示例。如果您正苦于以下问题:Java GoogleAccountCredential类的具体用法?Java GoogleAccountCredential怎么用?Java GoogleAccountCredential使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GoogleAccountCredential类属于com.google.api.client.googleapis.extensions.android.gms.auth包,在下文中一共展示了GoogleAccountCredential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initFileStorage

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
private void initFileStorage(FileStorageSetupActivity setupAct) {
	Activity activity = (Activity)setupAct;

	if (PROCESS_NAME_SELECTFILE.equals(setupAct.getProcessName()))
       {
           GoogleAccountCredential credential = createCredential(activity.getApplicationContext());

           logDebug("starting REQUEST_ACCOUNT_PICKER");
           activity.startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
       }

	if (PROCESS_NAME_FILE_USAGE_SETUP.equals(setupAct.getProcessName()))
       {
           initializeAccountOrPath(setupAct, setupAct.getPath());
       }
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:17,代码来源:GoogleDriveFileStorage.java

示例2: YouTubeSingleton

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
private YouTubeSingleton() {

        credential = GoogleAccountCredential.usingOAuth2(
                YTApplication.getAppContext(), Arrays.asList(SCOPES))
                .setBackOff(new ExponentialBackOff());

        youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest httpRequest) throws IOException {

            }
        }).setApplicationName(YTApplication.getAppContext().getString(R.string.app_name))
                .build();

        youTubeWithCredentials = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
                .setApplicationName(YTApplication.getAppContext().getString(R.string.app_name))
                .build();
    }
 
开发者ID:pawelpaszki,项目名称:youtube_background_android,代码行数:19,代码来源:YouTubeSingleton.java

示例3: initGAEService

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
private void initGAEService() {
    if (service != null) {
        return;
    }
    if (mGoogleSignInAccount == null) {
        return;
    }
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(mContext,
            "server:client_id:" + Constants.SERVER_CLIENT_ID);
    credential.setSelectedAccountName(mGoogleSignInAccount.getEmail());
    Log.d(TAG, "credential account name" + credential.getSelectedAccountName());
    U2fRequestHandler.Builder builder = new U2fRequestHandler.Builder(
            AndroidHttp.newCompatibleTransport(),
            new AndroidJsonFactory(), credential)
            .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                @Override
                public void initialize(
                        AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                        throws IOException {
                    abstractGoogleClientRequest.setDisableGZipContent(true);
                }
            });
    service = builder.build();
}
 
开发者ID:googlesamples,项目名称:android-fido,代码行数:25,代码来源:GAEService.java

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

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

示例6: YouTubeSingleton

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
private YouTubeSingleton(Context context)
{
    String appName = context.getString(R.string.app_name);
    credential = GoogleAccountCredential
            .usingOAuth2(context, Arrays.asList(SCOPES))
            .setBackOff(new ExponentialBackOff());

    youTube = new YouTube.Builder(
            new NetHttpTransport(),
            new JacksonFactory(),
            new HttpRequestInitializer()
            {
                @Override
                public void initialize(HttpRequest httpRequest) throws IOException {}
            }
    ).setApplicationName(appName).build();

    youTubeWithCredentials = new YouTube.Builder(
            new NetHttpTransport(),
            new JacksonFactory(),
            credential
    ).setApplicationName(appName).build();
}
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:24,代码来源:YouTubeSingleton.java

示例7: init

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
private void init() {
    // Initializing Internet Checker
    internetDetector = new InternetDetector(getApplicationContext());

    // Initialize credentials and service object.
    mCredential = GoogleAccountCredential.usingOAuth2(
            getApplicationContext(), Arrays.asList(SCOPES))
            .setBackOff(new ExponentialBackOff());

    // Initializing Progress Dialog
    mProgress = new ProgressDialog(this);
    mProgress.setMessage("Sending...");

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    sendFabButton = (FloatingActionButton) findViewById(R.id.fab);
    edtToAddress = (EditText) findViewById(R.id.to_address);
    edtSubject = (EditText) findViewById(R.id.subject);
    edtMessage = (EditText) findViewById(R.id.body);
    edtAttachmentData = (EditText) findViewById(R.id.attachmentData);

}
 
开发者ID:androidmads,项目名称:JavaMailwithGmailApi,代码行数:23,代码来源:MainActivity.java

示例8: setPermission

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
private boolean setPermission(Track track, String tableId) throws IOException, GoogleAuthException {
  boolean defaultTablePublic = PreferencesUtils.getBoolean(context,
      R.string.export_google_fusion_tables_public_key,
      PreferencesUtils.EXPORT_GOOGLE_FUSION_TABLES_PUBLIC_DEFAULT);
  if (!defaultTablePublic) {
    return true;
  }
  GoogleAccountCredential driveCredential = SendToGoogleUtils.getGoogleAccountCredential(
      context, account.name, SendToGoogleUtils.DRIVE_SCOPE);
  if (driveCredential == null) {
    return false;
  }
  Drive drive = SyncUtils.getDriveService(driveCredential);
  Permission permission = new Permission();
  permission.setRole("reader");
  permission.setType("anyone");
  permission.setValue("");   
  drive.permissions().insert(tableId, permission).execute();
  
  shareUrl = SendFusionTablesUtils.getMapUrl(track, tableId);
  return true;
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:23,代码来源:SendFusionTablesAsyncTask.java

示例9: searchSpreadsheets

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
/**
 * Searches Google Spreadsheets.
 * 
 * @param context the context
 * @param accountName the account name
 * @return the list of spreadsheets matching the title. Null if unable to
 *         search.
 */
public static List<File> searchSpreadsheets(Context context, String accountName) {
  try {
    GoogleAccountCredential googleAccountCredential = SendToGoogleUtils
        .getGoogleAccountCredential(context, accountName, SendToGoogleUtils.DRIVE_SCOPE);
    if (googleAccountCredential == null) {
      return null;
    }

    Drive drive = SyncUtils.getDriveService(googleAccountCredential);
    com.google.api.services.drive.Drive.Files.List list = drive.files().list().setQ(String.format(
        Locale.US, SendSpreadsheetsAsyncTask.GET_SPREADSHEET_QUERY, SPREADSHEETS_NAME));
    return list.execute().getItems();
  } catch (Exception e) {
    Log.e(TAG, "Unable to search spreadsheets.", e);
  }
  return null;
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:26,代码来源:GoogleUtils.java

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

示例11: get

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
public static Messaging get(Context context){
    if (messagingService == null) {
        SharedPreferences settings = context.getSharedPreferences(
                "Watchpresenter", Context.MODE_PRIVATE);
        final String accountName = settings.getString(Constants.PREF_ACCOUNT_NAME, null);
        if(accountName == null){
            Log.i(Constants.LOG_TAG, "Cannot send message. No account name found");
        }
        else {
            GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context,
                    "server:client_id:" + Constants.ANDROID_AUDIENCE);
            credential.setSelectedAccountName(accountName);
            Messaging.Builder builder = new Messaging.Builder(AndroidHttp.newCompatibleTransport(),
                    new GsonFactory(), credential)
                    .setRootUrl(Constants.SERVER_URL);

            messagingService = builder.build();
        }
    }
    return messagingService;
}
 
开发者ID:google,项目名称:watchpresenter,代码行数:22,代码来源:MessagingService.java

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

示例13: onAuthentication

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
@Override
public void onAuthentication(Credentials credentials) {
    Log.i(TAG, "Auth ok! User has given us all google requested permissions.");
    AuthenticationAPIClient client = new AuthenticationAPIClient(getAccount());
    client.tokenInfo(credentials.getIdToken())
            .start(new BaseCallback<UserProfile, AuthenticationException>() {
                @Override
                public void onSuccess(UserProfile payload) {
                    final GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(FilesActivity.this, Collections.singletonList(DriveScopes.DRIVE_METADATA_READONLY));
                    credential.setSelectedAccountName(payload.getEmail());
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            new FetchFilesTask().execute(credential);
                        }
                    });
                }

                @Override
                public void onFailure(AuthenticationException error) {
                }
            });

}
 
开发者ID:auth0,项目名称:Lock-Google.Android,代码行数:25,代码来源:FilesActivity.java

示例14: sync

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
private static void sync(Context context, boolean fullSync) {
  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
  GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context,
      "server:client_id:988087637760-6rhh5v6lhgjobfarparsomd4gectmk1v.apps.googleusercontent.com");
  String accountName = preferences.getString(PREF_ACCOUNT_NAME, null);
  if (accountName == null || accountName.isEmpty()) {
    // If you haven't set up an account yet, then we can't sync anyway.
    Log.w(TAG, "No account set, cannot sync!");
    return;
  }

  boolean hasGetAccountsPermission = ContextCompat.checkSelfPermission(
      context, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED;
  if (!hasGetAccountsPermission) {
    Log.w(TAG, "Don't have GET_ACCOUNTS permission, can't sync.");
    return;
  }

  Log.d(TAG, "Using account: " + accountName);
  credential.setSelectedAccountName(accountName);

  Syncsteps.Builder builder = new Syncsteps.Builder(
      AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential);
  builder.setApplicationName("Steptastic");
  new StepSyncer(context, builder.build(), fullSync).sync();
}
 
开发者ID:codeka,项目名称:steptastic,代码行数:27,代码来源:StepSyncer.java

示例15: updateRegStatus

import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; //导入依赖的package包/类
/**
 * Determine if user is registered for the conference and update shared preferences with result.
 *
 * @throws IOException If unable to verify user status
 */
private void updateRegStatus() throws Exception {
    // Build auth tokens
    GoogleAccountCredential credential = getGoogleCredential();
    String fbToken = getFirebaseToken();

    LOGD(TAG, "Firebase token: " + fbToken);
    LOGD(TAG, "Authenticating as: " + credential.getSelectedAccountName());

    // Communicate with server
    boolean isRegistered;
    isRegistered = isRegisteredAttendee(credential, fbToken);
    LOGD(TAG, "Conference attendance status: " +
            (isRegistered ? "REGISTERED" : "NOT_REGISTERED"));

    RegistrationUtils.setRegisteredAttendee(getApplicationContext(), isRegistered);
    RegistrationUtils.updateRegCheckTimestamp(this);
}
 
开发者ID:google,项目名称:iosched,代码行数:23,代码来源:RegistrationStatusService.java


注:本文中的com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。