本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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");
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}