本文整理汇总了Java中com.google.android.gms.auth.GoogleAuthException类的典型用法代码示例。如果您正苦于以下问题:Java GoogleAuthException类的具体用法?Java GoogleAuthException怎么用?Java GoogleAuthException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GoogleAuthException类属于com.google.android.gms.auth包,在下文中一共展示了GoogleAuthException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getToken
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
private void getToken(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String email = sharedPreferences.getString(Constants.KEY_EMAIL, null);
mUserGoogleId = sharedPreferences.getString(Constants.KEY_USER_GOOGLE_ID, null);
mUserUID = sharedPreferences.getString(Constants.KEY_USER_UID, null); //firebase userId
try {
String scope = String.format("oauth2:%s", "https://picasaweb.google.com/data/");
String token = null;
if (email != null) {
token = GoogleAuthUtil.getToken(context, email, scope);
}
Log.i(TAG, "Get Token\n" +
"2 Picasa client " + mPicasaClient + "\n" +
"2 Picasa service " + mPicasaService + "\n" +
"--- Google token " + token);
mPicasaClient.createService(token);
mPicasaService = mPicasaClient.getPicasaService();
} catch (IOException | GoogleAuthException e) {
e.printStackTrace();
}
}
示例2: handleSignInResult
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
protected void handleSignInResult(GoogleSignInResult result) {
Schedulers.newThread()
.scheduleDirect(() -> {
if (result.isSuccess()) {
if (result.getSignInAccount() != null && result.getSignInAccount().getAccount() != null) {
Account account = result.getSignInAccount().getAccount();
try {
String token = GoogleAuthUtil.getToken(activity, account, "oauth2:" + SCOPE_PICASA);
emitter.onSuccess(new GoogleSignIn.SignInAccount(token, result.getSignInAccount()));
} catch (IOException | GoogleAuthException e) {
emitter.onError(new SignInException("SignIn", e));
}
} else {
emitter.onError(new SignInException("SignIn", "getSignInAccount is null!", 0));
}
} else {
if (result.getStatus().getStatusCode() == CommonStatusCodes.SIGN_IN_REQUIRED) {
emitter.onError(new SignInRequiredException());
} else {
emitter.onError(new SignInException("SignIn", result.getStatus().getStatusMessage(), result.getStatus().getStatusCode()));
}
}
});
}
示例3: authenticate
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
@Override
public Request authenticate(Route route, Response response) throws IOException {
Log.d(TAG, "Re-authenticating requests");
if (responseCount(response) >= 3) {
return null; // If we've failed 3 times, give up. - in real life, never give up!!
} else {
try {
if (mContext == null)
Log.d(TAG, "Context is null");
String token = GoogleAuthUtil.getToken(mContext, Utils.getLoginEmail(mContext), Constants.URL_SHORTNER_SCOPE);
Log.d(TAG, "New token is " + token);
Utils.setAuthToken(mContext, token);
return response.request().newBuilder()
.header("Authorization", "Bearer " + Utils.getAuthToken(mContext))
.build();
} catch (GoogleAuthException e) {
e.printStackTrace();
return null;
}
}
}
示例4: setPermission
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的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;
}
示例5: setUpForSyncTest
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
/**
* Sets up sync tests.
*
* @param instrumentation the instrumentation is used for test
* @param trackListActivity the startup activity
* @return a Google Drive object
*/
public static Drive setUpForSyncTest(Instrumentation instrumentation,
TrackListActivity trackListActivity) throws IOException, GoogleAuthException {
if (!isCheckedRunSyncTest || RunConfiguration.getInstance().getRunSyncTest()) {
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
}
if (!isCheckedRunSyncTest) {
isCheckedRunSyncTest = true;
}
if (RunConfiguration.getInstance().getRunSyncTest()) {
enableSync(GoogleUtils.ACCOUNT_1);
Drive drive1 = getGoogleDrive(EndToEndTestUtils.trackListActivity.getApplicationContext());
removeKMLFiles(drive1);
EndToEndTestUtils.deleteAllTracks();
enableSync(GoogleUtils.ACCOUNT_2);
Drive drive2 = getGoogleDrive(EndToEndTestUtils.trackListActivity.getApplicationContext());
removeKMLFiles(drive2);
EndToEndTestUtils.deleteAllTracks();
return drive2;
}
return null;
}
示例6: authenticate
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
protected String authenticate(Context context, String mGoogleUserName)
throws IOException, GoogleAuthException,
GooglePlayServicesAvailabilityException,
UserRecoverableAuthException {
// use google auth utils to get oauth2 token
String scope = "oauth2:https://www.googleapis.com/auth/mapsengine https://picasaweb.google.com/data/";
String token = null;
if (mGoogleUserName == null) {
Log.e(tag, "Google user not set");
return null;
}
token = GoogleAuthUtil.getToken(context, mGoogleUserName, scope);
return token;
}
示例7: fetchToken
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
/**
* Gets an authentication token from Google and handles any
* GoogleAuthException that may occur.
*/
protected String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
} catch (UserRecoverableAuthException userRecoverableException) {
// GooglePlayServices.apk is either old, disabled, or not present
// so we need to show the user some UI in the activity to recover.
handleException(userRecoverableException);
} catch (GoogleAuthException fatalException) {
// Some other type of unrecoverable exception has occurred.
// Report and log the error as appropriate for your app.
// LogHelper.LOGD("GoogleAuthProvider","GetUserNameTask: " + fatalException.getMessage());
// Toast.makeText(mActivity, fatalException.getMessage(), Toast.LENGTH_SHORT).show();
if (getAuthCallback() != null) {
getAuthCallback().onError(fatalException);
}
}
return null;
}
示例8: execute
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
@Override
public Response execute(Request request) throws IOException {
try {
List<Header> headers = new LinkedList<Header>(request.getHeaders());
// if logged in add auth header
Optional<Account> account = loginManager.getAccount();
if (account.isPresent()) {
String token = loginManager.getToken(account.get());
Header authHeader = new Header("Authorization", "Bearer " + token);
headers.add(authHeader);
}
Request signedRequest = new Request(
request.getMethod(),
request.getUrl(),
headers,
request.getBody());
return super.execute(signedRequest);
} catch (GoogleAuthException gae) {
throw new IOException(gae);
}
}
示例9: fetchToken
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
/**
* Gets an authentication token from Google and handles any
* GoogleAuthException that may occur.
*/
protected String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getToken(MainActivity.this, mEmailText, mScope);
} catch (UserRecoverableAuthException userRecoverableException) {
// GooglePlayServices.apk is either old, disabled, or not present
// so we need to show the user some UI in the activity to recover.
//mActivity.handleException(userRecoverableException);
//Log.e(TAG, userRecoverableException.getMessage(), userRecoverableException);
mException = userRecoverableException;
} catch (GoogleAuthException fatalException) {
// Some other type of unrecoverable exception has occurred.
// Report and log the error as appropriate for your app.
Log.e(TAG, fatalException.getMessage(), fatalException);
}
return null;
}
示例10: getGoogleAuthToken
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
private String getGoogleAuthToken() throws IOException {
String googleUserName = PrefsUtil.retrieveGoogleTasksUser(mContext);
String token = "";
try {
Log.d(TAG, "getGoogleAuthToken... "+googleUserName);
token = GoogleAuthUtil.getTokenWithNotification(mContext,
googleUserName, GoogleTaskApiService.SCOPE, null);
} catch (UserRecoverableNotifiedException userNotifiedException) {
// Notification has already been pushed.
// Continue without token or stop background task.
} catch (GoogleAuthException authEx) {
// This is likely unrecoverable.
Log.e(TAG,
"Unrecoverable authentication exception: "
+ authEx.getMessage(), authEx);
}
return token;
}
示例11: fetchToken
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
/**
* Get a authentication token if one is not available. If the error was recoverable then a
* notification will automatically be pushed. The callback provided will be fired once the
* notification is addressed by the user successfully. If the error is not recoverable then
* it displays the error message on parent activity.
*/
@Override
protected String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getTokenWithNotification(
mActivity, mEmail, mScope, null, makeCallback(mEmail));
} catch (UserRecoverableNotifiedException userRecoverableException) {
// Unable to authenticate, but the user can fix this.
// Because we've used getTokenWithNotification(), a Notification is
// created automatically so the user can recover from the error
onError("Could not fetch token.", null);
} catch (GoogleAuthException fatalException) {
onError("Unrecoverable error " + fatalException.getMessage(), fatalException);
}
return null;
}
示例12: fetchToken
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
/**
* Fetches an access token from the G+ API
* @return the access token
* @throws IOException
*/
protected String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getToken(
mContext,
Plus.AccountApi.getAccountName(mGoogleApiClient),
"oauth2:" + SCOPES);
} catch (UserRecoverableAuthException userRecoverableException) {
// GooglePlayServices.apk is either old, disabled, or not present
// so we need to show the user some UI in the activity to recover.
Log.e(TAG, userRecoverableException.toString());
} catch (GoogleAuthException fatalException) {
// Some other type of unrecoverable exception has occurred.
// Report and log the error as appropriate for your app.
Log.e(TAG, fatalException.toString());
}
return null;
}
示例13: logAndShow
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
/**
* Logs the given throwable and shows an error alert dialog with its
* message.
*
* @param activity
* activity
* @param tag
* log tag to use
* @param t
* throwable to log and show
*/
public static void logAndShow(Activity activity, String tag, Throwable t) {
Log.e(tag, "Error", t);
String message = t.getMessage();
if (t instanceof GoogleJsonResponseException) {
GoogleJsonError details = ((GoogleJsonResponseException) t)
.getDetails();
if (details != null) {
message = details.getMessage();
}
} else if (t.getCause() instanceof OperationCanceledException) {
message = ((OperationCanceledException) t.getCause()).getMessage();
} else if (t.getCause() instanceof GoogleAuthException) {
message = ((GoogleAuthException) t.getCause()).getMessage();
} else if (t instanceof IOException) {
if (t.getMessage() == null) {
message = "IOException";
}
}
Log.d(tag, message);
ToastHelper.showErrorToast(activity,
activity.getResources().getString(R.string.error));
}
示例14: fetchToken
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
/**
* Get a authentication token if one is not available. If the error is not
* recoverable then it displays the error message on parent activity.
*/
private String fetchToken() {
try {
String token = GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
return token;
} catch (GooglePlayServicesAvailabilityException playEx) {
// GooglePlayServices.apk is either old, disabled, or not present.
mActivity.showErrorDialog(playEx.getConnectionStatusCode());
} catch (UserRecoverableAuthException userRecoverableException) {
// Unable to authenticate, but the user can fix this.
// Forward the user to the appropriate activity.
mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
} catch (GoogleAuthException fatalException) {
mActivity.showErrorDialog(ConnectionResult.INTERNAL_ERROR);
} catch (IOException e) {
mActivity.showErrorDialog(ConnectionResult.NETWORK_ERROR);
}
return null;
}
示例15: createSheet
import com.google.android.gms.auth.GoogleAuthException; //导入依赖的package包/类
public static void createSheet(String sheetName) throws IOException, GoogleAuthException {
Script mService = getAccessor();
Object[] params = {sheetName};
List<Object> paramList = Arrays.asList(params);
// Create an execution request object.
ExecutionRequest request = new ExecutionRequest()
.setFunction("create")
.setParameters(paramList);
// Make the request.
Operation op = mService.scripts().run(scriptId, request).execute();
// Print results of request.
if (op.getError() != null) {
throw new IOException(getScriptError(op));
}
/*if (op.getResponse() != null && op.getResponse().get("result") != null) {
// The result provided by the API needs to be cast into
// the correct type, based upon what types the Apps Script
// function returns.
}*/
}