Search in sources :

Example 26 with FacebookException

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();
            }
        }
    };
}
Also used : LoginManager(com.facebook.login.LoginManager) ProfileTracker(com.facebook.ProfileTracker) FacebookException(com.facebook.FacebookException) AccessToken(com.facebook.AccessToken) LoginResult(com.facebook.login.LoginResult) Profile(com.facebook.Profile)

Example 27 with FacebookException

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);
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) FacebookException(com.facebook.FacebookException) JSONException(org.json.JSONException) FacebookException(com.facebook.FacebookException) JSONException(org.json.JSONException)

Example 28 with FacebookException

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);
}
Also used : FacebookException(com.facebook.FacebookException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 29 with FacebookException

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) {
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) FacebookException(com.facebook.FacebookException) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with FacebookException

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);
}
Also used : FacebookException(com.facebook.FacebookException) KlyphPlacePickerFragment(com.facebook.widget.KlyphPlacePickerFragment) PickerFragment(com.facebook.widget.PickerFragment) Intent(android.content.Intent) GraphPlace(com.facebook.model.GraphPlace)

Aggregations

FacebookException (com.facebook.FacebookException)70 Bundle (android.os.Bundle)24 JSONObject (org.json.JSONObject)24 JSONException (org.json.JSONException)19 Bitmap (android.graphics.Bitmap)13 GraphRequest (com.facebook.GraphRequest)10 JSONArray (org.json.JSONArray)10 Intent (android.content.Intent)9 Uri (android.net.Uri)8 GraphResponse (com.facebook.GraphResponse)8 URISyntaxException (java.net.URISyntaxException)8 AccessToken (com.facebook.AccessToken)7 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)5 FacebookRequestError (com.facebook.FacebookRequestError)5 LoginResult (com.facebook.login.LoginResult)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 InputStreamReader (java.io.InputStreamReader)5 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5