Java Code Examples for com.facebook.FacebookException

The following examples show how to use com.facebook.FacebookException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: UberClone   Source File: Login.java    License: MIT License 7 votes vote down vote up
private void setupFacebookStuff() {

        // This should normally be on your application class
        FacebookSdk.sdkInitialize(getApplicationContext());

        mLoginManager = LoginManager.getInstance();
        mFacebookCallbackManager = CallbackManager.Factory.create();

        LoginManager.getInstance().registerCallback(mFacebookCallbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                //login
                firebaseHelper.registerByFacebookAccount();
            }

            @Override
            public void onCancel() {
                Toast.makeText(Login.this,"The login was canceled",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(FacebookException error) {
                Toast.makeText(Login.this,"There was an error in the login",Toast.LENGTH_SHORT).show();
            }
        });
    }
 
Example 2
Source Project: kognitivo   Source File: WebDialogParameters.java    License: Apache License 2.0 6 votes vote down vote up
public static Bundle create(ShareOpenGraphContent shareOpenGraphContent) {
    Bundle params = new Bundle();

    Utility.putNonEmptyString(
            params,
            ShareConstants.WEB_DIALOG_PARAM_ACTION_TYPE,
            shareOpenGraphContent.getAction().getActionType());

    try {
        JSONObject ogJSON = ShareInternalUtility.toJSONObjectForWeb(shareOpenGraphContent);
        ogJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject(ogJSON, false);
        if (ogJSON != null) {
            Utility.putNonEmptyString(
                    params,
                    ShareConstants.WEB_DIALOG_PARAM_ACTION_PROPERTIES,
                    ogJSON.toString());
        }
    } catch (JSONException e) {
        throw new FacebookException("Unable to serialize the ShareOpenGraphContent to JSON", e);
    }

    return params;
}
 
Example 3
Source Project: Learning-Resources   Source File: FireSignin.java    License: MIT License 6 votes vote down vote up
private void signInFacebook() {

        mPrgrsbrMain.setVisibility(View.VISIBLE);
        LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"));
        LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {

                // Facebook Sign In was successful, authenticate with Firebase
                firebaseAuthWithFacebook(loginResult.getAccessToken());
            }

            @Override
            public void onCancel() {
                LogManager.printLog(LOGTYPE_DEBUG, "facebook:onCancel");
                mPrgrsbrMain.setVisibility(View.GONE);
            }

            @Override
            public void onError(FacebookException error) {
                Log.d(LOG_TAG, "facebook:onError", error);
                mPrgrsbrMain.setVisibility(View.GONE);
            }
        });
    }
 
Example 4
Source Project: barterli_android   Source File: ProfilePictureView.java    License: Apache License 2.0 6 votes vote down vote up
private void processResponse(ImageResponse response) {
    // First check if the response is for the right request. We may have:
    // 1. Sent a new request, thus super-ceding this one.
    // 2. Detached this view, in which case the response should be discarded.
    if (response.getRequest() == lastRequest) {
        lastRequest = null;
        Bitmap responseImage = response.getBitmap();
        Exception error = response.getError();
        if (error != null) {
            OnErrorListener listener = onErrorListener;
            if (listener != null) {
                listener.onError(new FacebookException(
                        "Error in downloading profile picture for profileId: " + getProfileId(), error));
            } else {
                Logger.log(LoggingBehavior.REQUESTS, Log.ERROR, TAG, error.toString());
            }
        } else if (responseImage != null) {
            setImageBitmap(responseImage);

            if (response.isCachedRedirect()) {
                sendImageRequest(false);
            }
        }
    }
}
 
Example 5
Source Project: kognitivo   Source File: ShareInternalUtility.java    License: Apache License 2.0 6 votes vote down vote up
public static void registerSharerCallback(
        final int requestCode,
        final CallbackManager callbackManager,
        final FacebookCallback<Sharer.Result> callback) {
    if (!(callbackManager instanceof CallbackManagerImpl)) {
        throw new FacebookException("Unexpected CallbackManager, " +
                "please use the provided Factory.");
    }

    ((CallbackManagerImpl) callbackManager).registerCallback(
            requestCode,
            new CallbackManagerImpl.Callback() {
                @Override
                public boolean onActivityResult(int resultCode, Intent data) {
                    return handleActivityResult(
                            requestCode,
                            resultCode,
                            data,
                            getShareResultProcessor(callback));
                }
            });
}
 
Example 6
Source Project: social-app-android   Source File: LoginActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void initFacebookSignIn() {
    mCallbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            LogUtil.logDebug(TAG, "facebook:onSuccess:" + loginResult);
            presenter.handleFacebookSignInResult(loginResult);
        }

        @Override
        public void onCancel() {
            LogUtil.logDebug(TAG, "facebook:onCancel");
        }

        @Override
        public void onError(FacebookException error) {
            LogUtil.logError(TAG, "facebook:onError", error);
            showSnackBar(error.getMessage());
        }
    });

    findViewById(R.id.facebookSignInButton).setOnClickListener(v -> presenter.onFacebookSignInClick());
}
 
Example 7
Source Project: kognitivo   Source File: VideoUploader.java    License: Apache License 2.0 6 votes vote down vote up
private static void issueResponse(
        final UploadContext uploadContext,
        final FacebookException error,
        final String videoId) {
    // Remove the UploadContext synchronously
    // Once the UploadContext is removed, this is the only reference to it.
    removePendingUpload(uploadContext);

    Utility.closeQuietly(uploadContext.videoStream);

    if (uploadContext.callback != null) {
        if (error != null) {
            ShareInternalUtility.invokeOnErrorCallback(uploadContext.callback, error);
        } else if (uploadContext.isCanceled) {
            ShareInternalUtility.invokeOnCancelCallback(uploadContext.callback);
        } else {
            ShareInternalUtility.invokeOnSuccessCallback(uploadContext.callback, videoId);
        }
    }
}
 
Example 8
Source Project: kognitivo   Source File: VideoUploader.java    License: Apache License 2.0 6 votes vote down vote up
private void initialize()
        throws FileNotFoundException {
    ParcelFileDescriptor fileDescriptor = null;
    try {
        if (Utility.isFileUri(videoUri)) {
            fileDescriptor = ParcelFileDescriptor.open(
                    new File(videoUri.getPath()),
                    ParcelFileDescriptor.MODE_READ_ONLY);
            videoSize = fileDescriptor.getStatSize();
            videoStream = new ParcelFileDescriptor.AutoCloseInputStream(fileDescriptor);
        } else if (Utility.isContentUri(videoUri)) {
            videoSize = Utility.getContentSize(videoUri);
            videoStream = FacebookSdk
                    .getApplicationContext()
                    .getContentResolver()
                    .openInputStream(videoUri);
        } else {
            throw new FacebookException("Uri must be a content:// or file:// uri");
        }
    } catch (FileNotFoundException e) {
        Utility.closeQuietly(videoStream);

        throw e;
    }
}
 
Example 9
Source Project: kognitivo   Source File: VideoUploader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Bundle getParameters()
        throws IOException {
    Bundle parameters = new Bundle();
    parameters.putString(PARAM_UPLOAD_PHASE, PARAM_VALUE_UPLOAD_TRANSFER_PHASE);
    parameters.putString(PARAM_SESSION_ID, uploadContext.sessionId);
    parameters.putString(PARAM_START_OFFSET, chunkStart);

    byte[] chunk = getChunk(uploadContext, chunkStart, chunkEnd);
    if (chunk != null) {
        parameters.putByteArray(PARAM_VIDEO_FILE_CHUNK, chunk);
    } else {
        throw new FacebookException("Error reading video");
    }

    return parameters;
}
 
Example 10
Source Project: letv   Source File: NativeProtocol.java    License: Apache License 2.0 6 votes vote down vote up
public static FacebookException getExceptionFromErrorData(Bundle errorData) {
    if (errorData == null) {
        return null;
    }
    String type = errorData.getString(BRIDGE_ARG_ERROR_TYPE);
    if (type == null) {
        type = errorData.getString(STATUS_ERROR_TYPE);
    }
    String description = errorData.getString(BRIDGE_ARG_ERROR_DESCRIPTION);
    if (description == null) {
        description = errorData.getString(STATUS_ERROR_DESCRIPTION);
    }
    if (type == null || !type.equalsIgnoreCase(ERROR_USER_CANCELED)) {
        return new FacebookException(description);
    }
    return new FacebookOperationCanceledException(description);
}
 
Example 11
Source Project: AndroidBlueprints   Source File: FacebookHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Register call back manager.
 *
 * @param activity the activity
 */
private void registerCallBackManager(final Activity activity) {
    LoginManager.getInstance()
            .registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    mLoginResult = loginResult;
                    getUserProfile(activity);
                }

                @Override
                public void onCancel() {
                    mFacebookLoginResultCallBack.onFacebookLoginCancel();
                }

                @Override
                public void onError(FacebookException error) {
                    mFacebookLoginResultCallBack.onFacebookLoginError(error);
                }
            });
}
 
Example 12
Source Project: kognitivo   Source File: LoginClient.java    License: Apache License 2.0 6 votes vote down vote up
void authorize(Request request) {
    if (request == null) {
        return;
    }

    if (pendingRequest != null) {
        throw new FacebookException("Attempted to authorize while a request is pending.");
    }

    if (AccessToken.getCurrentAccessToken() != null && !checkInternetPermission()) {
        // We're going to need INTERNET permission later and don't have it, so fail early.
        return;
    }
    pendingRequest = request;
    handlersToTry = getHandlersToTry(request);
    tryNextHandler();
}
 
Example 13
Source Project: kognitivo   Source File: LoginManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Registers a login callback to the given callback manager.
 * @param callbackManager The callback manager that will encapsulate the callback.
 * @param callback The login callback that will be called on login completion.
 */
public void registerCallback(
        final CallbackManager callbackManager,
        final FacebookCallback<LoginResult> callback) {
    if (!(callbackManager instanceof CallbackManagerImpl)) {
        throw new FacebookException("Unexpected CallbackManager, " +
                "please use the provided Factory.");
    }
    ((CallbackManagerImpl) callbackManager).registerCallback(
            CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode(),
            new CallbackManagerImpl.Callback() {
                @Override
                public boolean onActivityResult(int resultCode, Intent data) {
                    return LoginManager.this.onActivityResult(
                            resultCode,
                            data,
                            callback);
                }
            }
    );
}
 
Example 14
Source Project: kognitivo   Source File: DialogPresenter.java    License: Apache License 2.0 6 votes vote down vote up
public static void setupAppCallForErrorResult(AppCall appCall, FacebookException exception) {
    if (exception == null) {
        return;
    }
    Validate.hasFacebookActivity(FacebookSdk.getApplicationContext());

    Intent errorResultIntent = new Intent();
    errorResultIntent.setClass(FacebookSdk.getApplicationContext(), FacebookActivity.class);
    errorResultIntent.setAction(FacebookActivity.PASS_THROUGH_CANCEL_ACTION);

    NativeProtocol.setupProtocolRequestIntent(
            errorResultIntent,
            appCall.getCallId().toString(),
            null,
            NativeProtocol.getLatestKnownVersion(),
            NativeProtocol.createBundleForException(exception));

    appCall.setRequestIntent(errorResultIntent);
}
 
Example 15
Source Project: edx-app-android   Source File: FacebookAuth.java    License: Apache License 2.0 6 votes vote down vote up
public FacebookAuth(Activity activity) {
    super(activity);
    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager,
            new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    if (callback != null) {
                        callback.onLogin(loginResult.getAccessToken().getToken());
                    }
                    logger.debug("Facebook Logged in successfully.");
                }

                @Override
                public void onCancel() {
                    logger.debug("Facebook Log in canceled.");
                }

                @Override
                public void onError(FacebookException error) {
                    logger.error(error);
                }
            });
}
 
Example 16
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}
 
Example 17
Source Project: android-paypal-example   Source File: LoginActivity.java    License: Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.fb_login)
public void setUpFacebookLoginButton() {
    LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email", "public_profile"));
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {
            if(!isNetworkConnected()){
                Snackbar.make(findViewById(android.R.id.content),"please check internet connection"
                        ,Snackbar.LENGTH_SHORT).show();
            }else{
                Snackbar.make(findViewById(android.R.id.content),"unexpected error,please try again later"
                        ,Snackbar.LENGTH_SHORT).show();
            }
        }
    });
}
 
Example 18
Source Project: barterli_android   Source File: FriendPickerFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
Request getRequestForLoadData(Session session) {
    if (adapter == null) {
        throw new FacebookException("Can't issue requests until Fragment has been created.");
    }

    String userToFetch = (userId != null) ? userId : "me";
    return createRequest(userToFetch, extraFields, session);
}
 
Example 19
Source Project: kognitivo   Source File: FacebookButtonBase.java    License: Apache License 2.0 5 votes vote down vote up
protected Activity getActivity() {
    Context context = getContext();
    while (!(context instanceof Activity) && context instanceof ContextWrapper) {
        context = ((ContextWrapper) context).getBaseContext();
    }

    if (context instanceof Activity) {
        return (Activity) context;
    }
    throw new FacebookException("Unable to get Activity.");
}
 
Example 20
Source Project: kognitivo   Source File: NativeDialogParameters.java    License: Apache License 2.0 5 votes vote down vote up
public static Bundle create(
        UUID callId,
        ShareContent shareContent,
        boolean shouldFailOnDataError) {
    Validate.notNull(shareContent, "shareContent");
    Validate.notNull(callId, "callId");

    Bundle nativeParams = null;
    if (shareContent instanceof ShareLinkContent) {
        final ShareLinkContent linkContent = (ShareLinkContent) shareContent;
        nativeParams = create(linkContent, shouldFailOnDataError);
    } else if (shareContent instanceof SharePhotoContent) {
        final SharePhotoContent photoContent = (SharePhotoContent) shareContent;
        List<String> photoUrls = ShareInternalUtility.getPhotoUrls(
                photoContent,
                callId);

        nativeParams = create(photoContent, photoUrls, shouldFailOnDataError);
    } else if (shareContent instanceof ShareVideoContent) {
        final ShareVideoContent videoContent = (ShareVideoContent) shareContent;
        String videoUrl = ShareInternalUtility.getVideoUrl(videoContent, callId);

        nativeParams = create(videoContent, videoUrl, shouldFailOnDataError);
    } else if (shareContent instanceof ShareOpenGraphContent) {
        final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent;
        try {
            JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall(
                    callId, openGraphContent);
            openGraphActionJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject(
                    openGraphActionJSON, false);
            nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError);
        } catch (final JSONException e) {
            throw new FacebookException(
                    "Unable to create a JSON Object from the provided ShareOpenGraphContent: "
                            + e.getMessage());
        }
    }

    return nativeParams;
}
 
Example 21
Source Project: kognitivo   Source File: ShareContentValidation.java    License: Apache License 2.0 5 votes vote down vote up
private static void validateLinkContent(
        ShareLinkContent linkContent, Validator validator) {
    Uri imageUrl = linkContent.getImageUrl();
    if (imageUrl != null && !Utility.isWebUri(imageUrl)) {
        throw new FacebookException("Image Url must be an http:// or https:// url");
    }
}
 
Example 22
Source Project: Abelana-Android   Source File: GraphObjectAdapter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @throws FacebookException if the GraphObject doesn't have an ID.
 */
String getIdOfGraphObject(T graphObject) {
    if (graphObject.asMap().containsKey(ID)) {
        Object obj = graphObject.getProperty(ID);
        if (obj instanceof String) {
            return (String) obj;
        }
    }
    throw new FacebookException("Received an object without an ID.");
}
 
Example 23
Source Project: kognitivo   Source File: ShareContentValidation.java    License: Apache License 2.0 5 votes vote down vote up
private static void validateVideo(ShareVideo video, Validator validator) {
    if (video == null) {
        throw new FacebookException("Cannot share a null ShareVideo");
    }

    Uri localUri = video.getLocalUrl();
    if (localUri == null) {
        throw new FacebookException("ShareVideo does not have a LocalUrl specified");
    }

    if (!Utility.isContentUri(localUri) && !Utility.isFileUri(localUri)) {
        throw new FacebookException("ShareVideo must reference a video that is on the device");
    }
}
 
Example 24
Source Project: kognitivo   Source File: ShareContentValidation.java    License: Apache License 2.0 5 votes vote down vote up
private static void validateOpenGraphAction(
        ShareOpenGraphAction openGraphAction,
        Validator validator) {
    if (openGraphAction == null) {
        throw new FacebookException("Must specify a non-null ShareOpenGraphAction");
    }

    if (Utility.isNullOrEmpty(openGraphAction.getActionType())) {
        throw new FacebookException("ShareOpenGraphAction must have a non-empty actionType");
    }

    validator.validate((ShareOpenGraphValueContainer) openGraphAction, false);
}
 
Example 25
Source Project: Klyph   Source File: LoginButton.java    License: MIT License 5 votes vote down vote up
void handleError(Exception exception) {
    if (properties.onErrorListener != null) {
        if (exception instanceof FacebookException) {
            properties.onErrorListener.onError((FacebookException)exception);
        } else {
            properties.onErrorListener.onError(new FacebookException(exception));
        }
    }
}
 
Example 26
@Override
public int getItemViewType(int position) {
    SectionAndItem<T> sectionAndItem = getSectionAndItem(position);
    switch (sectionAndItem.getType()) {
        case SECTION_HEADER:
            return HEADER_VIEW_TYPE;
        case GRAPH_OBJECT:
            return GRAPH_OBJECT_VIEW_TYPE;
        case ACTIVITY_CIRCLE:
            return ACTIVITY_CIRCLE_VIEW_TYPE;
        default:
            throw new FacebookException("Unexpected type of section and item.");
    }
}
 
Example 27
Source Project: kognitivo   Source File: ShareContentValidation.java    License: Apache License 2.0 5 votes vote down vote up
private static void validateOpenGraphKey(String key, boolean requireNamespace) {
    if (!requireNamespace) {
        return;
    }

    String[] components = key.split(":");
    if (components.length < 2) {
        throw new FacebookException("Open Graph keys must be namespaced: %s", key);
    }
    for (String component : components) {
        if (component.isEmpty()) {
            throw new FacebookException("Invalid key found in Open Graph dictionary: %s", key);
        }
    }
}
 
Example 28
Source Project: Abelana-Android   Source File: FbDialog.java    License: Apache License 2.0 5 votes vote down vote up
private void setDialogListener(DialogListener listener) {
    this.mListener = listener;
    setOnCompleteListener(new OnCompleteListener() {
        @Override
        public void onComplete(Bundle values, FacebookException error) {
            callDialogListener(values, error);
        }
    });
}
 
Example 29
Source Project: kognitivo   Source File: ShareInternalUtility.java    License: Apache License 2.0 5 votes vote down vote up
public static void invokeCallbackWithException(
        FacebookCallback<Sharer.Result> callback,
        final Exception exception) {
    if (exception instanceof FacebookException) {
        invokeOnErrorCallback(callback, (FacebookException) exception);
        return;
    }
    invokeCallbackWithError(
            callback,
            "Error preparing share content: " + exception.getLocalizedMessage());
}
 
Example 30
Source Project: kognitivo   Source File: ShareInternalUtility.java    License: Apache License 2.0 5 votes vote down vote up
static void invokeOnErrorCallback(
        FacebookCallback<Sharer.Result> callback,
        String message) {
    logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_ERROR, message);
    if (callback != null) {
        callback.onError(new FacebookException(message));
    }
}