use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class NativeAppLoginMethodHandler method handleResultOk.
private LoginClient.Result handleResultOk(LoginClient.Request request, Intent data) {
Bundle extras = data.getExtras();
String error = getError(extras);
String errorCode = extras.getString("error_code");
String errorMessage = getErrorMessage(extras);
String e2e = extras.getString(NativeProtocol.FACEBOOK_PROXY_AUTH_E2E_KEY);
if (!Utility.isNullOrEmpty(e2e)) {
logWebLoginCompleted(e2e);
}
if (error == null && errorCode == null && errorMessage == null) {
try {
AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(), extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB, request.getApplicationId());
return LoginClient.Result.createTokenResult(request, token);
} catch (FacebookException ex) {
return LoginClient.Result.createErrorResult(request, null, ex.getMessage());
}
} else if (ServerProtocol.errorsProxyAuthDisabled.contains(error)) {
return null;
} else if (ServerProtocol.errorsUserCanceled.contains(error)) {
return LoginClient.Result.createCancelResult(request, null);
} else {
return LoginClient.Result.createErrorResult(request, error, errorMessage, errorCode);
}
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class WebLoginMethodHandler method onComplete.
protected void onComplete(LoginClient.Request request, Bundle values, FacebookException error) {
LoginClient.Result outcome;
e2e = null;
if (values != null) {
// Actual e2e we got from the dialog should be used for logging.
if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) {
e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E);
}
try {
AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(), values, getTokenSource(), request.getApplicationId());
outcome = LoginClient.Result.createTokenResult(loginClient.getPendingRequest(), token);
// Ensure any cookies set by the dialog are saved
// This is to work around a bug where CookieManager may fail to instantiate if
// CookieSyncManager has never been created.
CookieSyncManager syncManager = CookieSyncManager.createInstance(loginClient.getActivity());
syncManager.sync();
saveCookieToken(token.getToken());
} catch (FacebookException ex) {
outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(), null, ex.getMessage());
}
} else {
if (error instanceof FacebookOperationCanceledException) {
outcome = LoginClient.Result.createCancelResult(loginClient.getPendingRequest(), "User canceled log in.");
} else {
// Something went wrong, don't log a completion event since it will skew timing
// results.
e2e = null;
String errorCode = null;
String errorMessage = error.getMessage();
if (error instanceof FacebookServiceException) {
FacebookRequestError requestError = ((FacebookServiceException) error).getRequestError();
errorCode = String.format(Locale.ROOT, "%d", requestError.getErrorCode());
errorMessage = requestError.toString();
}
outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(), null, errorMessage, errorCode);
}
}
if (!Utility.isNullOrEmpty(e2e)) {
logWebLoginCompleted(e2e);
}
loginClient.completeAndValidate(outcome);
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class LoginManager method onActivityResult.
boolean onActivityResult(int resultCode, Intent data, FacebookCallback<LoginResult> callback) {
FacebookException exception = null;
AccessToken newToken = null;
LoginClient.Result.Code code = LoginClient.Result.Code.ERROR;
Map<String, String> loggingExtras = null;
LoginClient.Request originalRequest = null;
boolean isCanceled = false;
if (data != null) {
LoginClient.Result result = data.getParcelableExtra(LoginFragment.RESULT_KEY);
if (result != null) {
originalRequest = result.request;
code = result.code;
if (resultCode == Activity.RESULT_OK) {
if (result.code == LoginClient.Result.Code.SUCCESS) {
newToken = result.token;
} else {
exception = new FacebookAuthorizationException(result.errorMessage);
}
} else if (resultCode == Activity.RESULT_CANCELED) {
isCanceled = true;
}
loggingExtras = result.loggingExtras;
}
} else if (resultCode == Activity.RESULT_CANCELED) {
isCanceled = true;
code = LoginClient.Result.Code.CANCEL;
}
if (exception == null && newToken == null && !isCanceled) {
exception = new FacebookException("Unexpected call to LoginManager.onActivityResult");
}
boolean wasLoginActivityTried = true;
//Sadly, there is no way to get activity context at this point.S
Context context = null;
logCompleteLogin(context, code, loggingExtras, exception, wasLoginActivityTried, originalRequest);
finishLogin(newToken, originalRequest, exception, isCanceled, callback);
return true;
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class ShareContentValidation method validateOpenGraphValueContainer.
private static void validateOpenGraphValueContainer(ShareOpenGraphValueContainer valueContainer, Validator validator, boolean requireNamespace) {
Set<String> keySet = valueContainer.keySet();
for (String key : keySet) {
validateOpenGraphKey(key, requireNamespace);
Object o = valueContainer.get(key);
if (o instanceof List) {
List list = (List) o;
for (Object objectInList : list) {
if (objectInList == null) {
throw new FacebookException("Cannot put null objects in Lists in " + "ShareOpenGraphObjects and ShareOpenGraphActions");
}
validateOpenGraphValueContainerObject(objectInList, validator);
}
} else {
validateOpenGraphValueContainerObject(o, validator);
}
}
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class DeviceAuthDialog method startLogin.
public void startLogin(final LoginClient.Request request) {
this.mRequest = request;
final Bundle parameters = new Bundle();
parameters.putString("scope", TextUtils.join(",", request.getPermissions()));
String redirectUriString = request.getDeviceRedirectUriString();
if (redirectUriString != null) {
parameters.putString("redirect_uri", redirectUriString);
}
String accessToken = Validate.hasAppID() + "|" + Validate.hasClientToken();
parameters.putString(GraphRequest.ACCESS_TOKEN_PARAM, accessToken);
parameters.putString(DeviceRequestsHelper.DEVICE_INFO_PARAM, DeviceRequestsHelper.getDeviceInfo());
GraphRequest graphRequest = new GraphRequest(null, DEVICE_LOGIN_ENDPOINT, parameters, HttpMethod.POST, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
if (isBeingDestroyed) {
return;
}
if (response.getError() != null) {
onError(response.getError().getException());
return;
}
JSONObject jsonObject = response.getJSONObject();
RequestState requestState = new RequestState();
try {
requestState.setUserCode(jsonObject.getString("user_code"));
requestState.setRequestCode(jsonObject.getString("code"));
requestState.setInterval(jsonObject.getLong("interval"));
} catch (JSONException ex) {
onError(new FacebookException(ex));
return;
}
setCurrentRequestState(requestState);
}
});
graphRequest.executeAsync();
}
Aggregations