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