use of com.facebook.FacebookOperationCanceledException in project Klyph by jonathangerbaud.
the class UserTimeline method publishFeedDialog.
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("from", KlyphSession.getSessionUserId());
params.putString("to", getElementId());
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(getActivity(), Session.getActiveSession(), params)).setOnCompleteListener(new WebDialog.OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getActivity(), R.string.message_successfully_published, Toast.LENGTH_SHORT).show();
loadNewest();
} else {
// User clicked the Cancel button
Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
// Toast.makeText(getActivity().getApplicationContext(),
// "Publish cancelled",
// Toast.LENGTH_SHORT).show();
} else {
AlertUtil.showAlert(getActivity(), R.string.error, R.string.publish_message_unknown_error, R.string.ok);
}
}
}).build();
feedDialog.show();
}
use of com.facebook.FacebookOperationCanceledException in project phonegap-facebook-plugin by Wizcorp.
the class FbDialog method callDialogListener.
private void callDialogListener(Bundle values, FacebookException error) {
if (mListener == null) {
return;
}
if (values != null) {
mListener.onComplete(values);
} else {
if (error instanceof FacebookDialogException) {
FacebookDialogException facebookDialogException = (FacebookDialogException) error;
DialogError dialogError = new DialogError(facebookDialogException.getMessage(), facebookDialogException.getErrorCode(), facebookDialogException.getFailingUrl());
mListener.onError(dialogError);
} else if (error instanceof FacebookOperationCanceledException) {
mListener.onCancel();
} else {
FacebookError facebookError = new FacebookError(error.getMessage());
mListener.onFacebookError(facebookError);
}
}
}
use of com.facebook.FacebookOperationCanceledException in project phonegap-facebook-plugin by Wizcorp.
the class ConnectPlugin method onSessionStateChange.
/*
* Handles session state changes
*/
private void onSessionStateChange(SessionState state, Exception exception) {
Log.d(TAG, "onSessionStateChange:" + state.toString());
if (exception != null && exception instanceof FacebookOperationCanceledException) {
// only handle FacebookOperationCanceledException to support
// SDK recovery behavior triggered by getUserInfo
Log.e(TAG, "exception:" + exception.toString());
handleError(exception, loginContext);
} else {
final Session session = Session.getActiveSession();
// Check if the session is open
if (state.isOpened()) {
if (loginContext != null) {
// Get user info
getUserInfo(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// Create a new result with response data
if (loginContext != null) {
if (response.getError() != null) {
loginContext.error(getFacebookRequestErrorResponse(response.getError()));
} else {
GraphObject graphObject = response.getGraphObject();
Log.d(TAG, "returning login object " + graphObject.getInnerJSONObject().toString());
userID = user.getId();
loginContext.success(getResponse());
loginContext = null;
}
} else {
// Just update the userID in case we force quit the application before
userID = user.getId();
}
}
});
} else if (graphContext != null) {
// Make the graph call
makeGraphCall();
}
} else if (state == SessionState.CLOSED_LOGIN_FAILED && loginContext != null) {
handleError(new FacebookAuthorizationException("Session was closed and was not closed normally"), loginContext);
}
}
}
use of com.facebook.FacebookOperationCanceledException 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.FacebookOperationCanceledException in project facebook-android-sdk by facebook.
the class WebViewLoginMethodHandlerTest method testWebViewHandlesCancel.
@Test
public void testWebViewHandlesCancel() {
WebViewLoginMethodHandler handler = new WebViewLoginMethodHandler(mockLoginClient);
LoginClient.Request request = createRequest();
handler.onWebDialogComplete(request, null, new FacebookOperationCanceledException());
ArgumentCaptor<LoginClient.Result> resultArgumentCaptor = ArgumentCaptor.forClass(LoginClient.Result.class);
verify(mockLoginClient, times(1)).completeAndValidate(resultArgumentCaptor.capture());
LoginClient.Result result = resultArgumentCaptor.getValue();
assertNotNull(result);
assertEquals(LoginClient.Result.Code.CANCEL, result.code);
assertNull(result.token);
assertNotNull(result.errorMessage);
}
Aggregations