use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class SettingsFragment method setUpCallbacks.
private void setUpCallbacks() {
callbackManager = CallbackManager.Factory.create();
LoginManager manager = LoginManager.getInstance();
manager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Profile.fetchProfileForCurrentAccessToken();
}
@Override
public void onError(FacebookException exception) {
AccessToken.setCurrentAccessToken(null);
currentUserChanged();
}
@Override
public void onCancel() {
AccessToken.setCurrentAccessToken(null);
currentUserChanged();
}
});
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
Slot currentSlot = slotManager.getSelectedSlot();
AccessToken currentAccessToken = AccessToken.getCurrentAccessToken();
if (currentSlot != null && currentAccessToken != null && currentProfile != null) {
currentSlot.setUserInfo(new UserInfo(currentProfile.getName(), currentAccessToken));
currentUserChanged();
}
}
};
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class AppLinkData method fetchDeferredAppLinkFromServer.
private static void fetchDeferredAppLinkFromServer(Context context, String applicationId, final CompletionHandler completionHandler) {
JSONObject deferredApplinkParams = new JSONObject();
try {
deferredApplinkParams.put("event", DEFERRED_APP_LINK_EVENT);
Utility.setAppEventAttributionParameters(deferredApplinkParams, AttributionIdentifiers.getAttributionIdentifiers(context), AppEventsLogger.getAnonymousAppDeviceGUID(context), FacebookSdk.getLimitEventAndDataUsage(context));
Utility.setAppEventExtendedDeviceInfoParameters(deferredApplinkParams, FacebookSdk.getApplicationContext());
deferredApplinkParams.put("application_package_name", context.getPackageName());
} catch (JSONException e) {
throw new FacebookException("An error occurred while preparing deferred app link", e);
}
String deferredApplinkUrlPath = String.format(DEFERRED_APP_LINK_PATH, applicationId);
AppLinkData appLinkData = null;
try {
GraphRequest deferredApplinkRequest = GraphRequest.newPostRequest(null, deferredApplinkUrlPath, deferredApplinkParams, null);
GraphResponse deferredApplinkResponse = deferredApplinkRequest.executeAndWait();
JSONObject jsonResponse = deferredApplinkResponse.getJSONObject();
if (jsonResponse != null) {
final String appLinkArgsJsonString = jsonResponse.optString(DEFERRED_APP_LINK_ARGS_FIELD);
final long tapTimeUtc = jsonResponse.optLong(DEFERRED_APP_LINK_CLICK_TIME_FIELD, -1);
final String appLinkClassName = jsonResponse.optString(DEFERRED_APP_LINK_CLASS_FIELD);
final String appLinkUrl = jsonResponse.optString(DEFERRED_APP_LINK_URL_FIELD);
if (!TextUtils.isEmpty(appLinkArgsJsonString)) {
appLinkData = createFromJson(appLinkArgsJsonString);
if (tapTimeUtc != -1) {
try {
if (appLinkData.arguments != null) {
appLinkData.arguments.put(ARGUMENTS_TAPTIME_KEY, tapTimeUtc);
}
if (appLinkData.argumentBundle != null) {
appLinkData.argumentBundle.putString(ARGUMENTS_TAPTIME_KEY, Long.toString(tapTimeUtc));
}
} catch (JSONException e) {
Log.d(TAG, "Unable to put tap time in AppLinkData.arguments");
}
}
if (appLinkClassName != null) {
try {
if (appLinkData.arguments != null) {
appLinkData.arguments.put(ARGUMENTS_NATIVE_CLASS_KEY, appLinkClassName);
}
if (appLinkData.argumentBundle != null) {
appLinkData.argumentBundle.putString(ARGUMENTS_NATIVE_CLASS_KEY, appLinkClassName);
}
} catch (JSONException e) {
Log.d(TAG, "Unable to put tap time in AppLinkData.arguments");
}
}
if (appLinkUrl != null) {
try {
if (appLinkData.arguments != null) {
appLinkData.arguments.put(ARGUMENTS_NATIVE_URL, appLinkUrl);
}
if (appLinkData.argumentBundle != null) {
appLinkData.argumentBundle.putString(ARGUMENTS_NATIVE_URL, appLinkUrl);
}
} catch (JSONException e) {
Log.d(TAG, "Unable to put tap time in AppLinkData.arguments");
}
}
}
}
} catch (Exception e) {
Utility.logd(TAG, "Unable to fetch deferred applink from server");
}
completionHandler.onDeferredAppLinkDataFetched(appLinkData);
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class WebViewLoginMethodHandlerTest method testWebViewHandlesError.
@Test
public void testWebViewHandlesError() {
WebViewLoginMethodHandler handler = new WebViewLoginMethodHandler(mockLoginClient);
LoginClient.Request request = createRequest();
handler.onWebDialogComplete(request, null, new FacebookException(ERROR_MESSAGE));
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.ERROR, result.code);
assertNull(result.token);
assertNotNull(result.errorMessage);
assertEquals(ERROR_MESSAGE, result.errorMessage);
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class LoginManagerTest method testLogInThrowsIfCannotStartFacebookActivity.
@Test
public void testLogInThrowsIfCannotStartFacebookActivity() {
doThrow(new ActivityNotFoundException()).when(mockActivity).startActivityForResult(any(Intent.class), anyInt());
LoginManager loginManager = new LoginManager();
try {
loginManager.logInWithReadPermissions(mockActivity, Arrays.asList("public_profile", "user_friends"));
fail();
} catch (FacebookException exception) {
}
}
use of com.facebook.FacebookException in project Klyph by jonathangerbaud.
the class PlacePickerActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
destroyed = false;
setTitle(R.string.choose_place);
placePickerFragment = (KlyphPlacePickerFragment) getSupportFragmentManager().findFragmentById(R.id.place_picker_fragment);
placePickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() {
@Override
public void onSelectionChanged(PickerFragment<?> fragment) {
GraphPlace place = placePickerFragment.getSelection();
if (place != null) {
Intent intent = new Intent();
intent.putExtra(KlyphBundleExtras.PLACE_ID, place.getId());
intent.putExtra(KlyphBundleExtras.PLACE_NAME, place.getName());
setResult(RESULT_OK, intent);
finish();
}
}
});
placePickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
@Override
public void onError(PickerFragment<?> fragment, FacebookException error) {
PlacePickerActivity.this.onError(error);
}
});
placePickerFragment.setShowTitleBar(false);
}
Aggregations