com.facebook.CallbackManager Java Examples

The following examples show how to use com.facebook.CallbackManager. 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 File: Login.java    From UberClone with 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 File: FacebookAuth.java    From edx-app-android with 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 #3
Source File: AccountNavigator.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
public AccountNavigator(BottomNavigationNavigator bottomNavigationNavigator,
    FragmentNavigator fragmentNavigator, AptoideAccountManager accountManager,
    ActivityNavigator activityNavigator, LoginManager facebookLoginManager,
    CallbackManager callbackManager, GoogleApiClient client,
    PublishRelay<FacebookLoginResult> facebookLoginSubject, String recoverPasswordUrl,
    AccountAnalytics accountAnalytics, ThemeManager themeManager) {
  this.bottomNavigationNavigator = bottomNavigationNavigator;
  this.fragmentNavigator = fragmentNavigator;
  this.accountManager = accountManager;
  this.activityNavigator = activityNavigator;
  this.facebookLoginManager = facebookLoginManager;
  this.callbackManager = callbackManager;
  this.client = client;
  this.facebookLoginSubject = facebookLoginSubject;
  this.recoverPasswordUrl = recoverPasswordUrl;
  this.accountAnalytics = accountAnalytics;
  this.themeManager = themeManager;
}
 
Example #4
Source File: LoginActivity.java    From android-paypal-example with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ButterKnife.bind(this);

    // [START initialize_auth]
    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();
    // [END initialize_auth]

    //initialize facebook callback
    callbackManager = CallbackManager.Factory.create();

}
 
Example #5
Source File: LoginDialogFragment.java    From openshop.io-android with MIT License 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Timber.d("%s - OnCreateView", this.getClass().getSimpleName());
    View view = inflater.inflate(R.layout.dialog_login, container, false);
    callbackManager = CallbackManager.Factory.create();

    loginBaseForm = view.findViewById(R.id.login_base_form);
    loginRegistrationForm = view.findViewById(R.id.login_registration_form);
    loginEmailForm = view.findViewById(R.id.login_email_form);
    loginEmailForgottenForm = view.findViewById(R.id.login_email_forgotten_form);

    prepareLoginFormNavigation(view);
    prepareInputBoxes(view);
    prepareActionButtons(view);
    return view;
}
 
Example #6
Source File: FacebookHelper.java    From social-login-helper-Deprecated- with MIT License 6 votes vote down vote up
public FacebookHelper(@NonNull FacebookListener facebookListener) {
  mListener = facebookListener;
  mCallBackManager = CallbackManager.Factory.create();
  FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() {
    @Override public void onSuccess(LoginResult loginResult) {
      mListener.onFbSignInSuccess(loginResult.getAccessToken().getToken(),
          loginResult.getAccessToken().getUserId());
    }

    @Override public void onCancel() {
      mListener.onFbSignInFail("User cancelled operation");
    }

    @Override public void onError(FacebookException e) {
      mListener.onFbSignInFail(e.getMessage());
    }
  };
  LoginManager.getInstance().registerCallback(mCallBackManager, mCallBack);
}
 
Example #7
Source File: LoginFragment.java    From HaiNaBaiChuan with Apache License 2.0 6 votes vote down vote up
private void initFaceBookLogin() {
    callbackManager = CallbackManager.Factory.create();
    btnLoginFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            showDialog();
            presenter.requestFacebook(loginResult);
            LogUtil.e2(loginResult.getAccessToken().toString());
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {

        }
    });
}
 
Example #8
Source File: LoginManager.java    From kognitivo with 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 #9
Source File: ShareInternalUtility.java    From kognitivo with 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 #10
Source File: FacebookImpl.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void askPublishPermissions(final LoginCallback cb) {
    if (AndroidNativeUtil.getActivity() == null) {
        throw new RuntimeException("Cannot ask for publish permissions when running in the background.");
    
    }
    if (loginLock) {
        return;
    }
    loginLock = true;

    LoginManager login = LoginManager.getInstance();
    final CallbackManager mCallbackManager = CallbackManager.Factory.create();
    final CodenameOneActivity activity = (CodenameOneActivity) AndroidNativeUtil.getActivity();
    activity.setIntentResultListener(new IntentResultListener() {

        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            mCallbackManager.onActivityResult(requestCode, resultCode, data);
            activity.restoreIntentResultListener();
        }
    });
    login.registerCallback(mCallbackManager, new FBCallback(cb));
    login.logInWithPublishPermissions(activity, PUBLISH_PERMISSIONS);
}
 
Example #11
Source File: ActivityMain.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
private void init() {
    UpodsApplication.initAllResources();
    vOverlay = findViewById(R.id.vOverlay);

    //Toolbar
    toolbar.inflateMenu(R.menu.menu_activity_main);
    toolbar.setOnMenuItemClickListener(this);
    toolbar.setTitleTextColor(getResources().getColor(R.color.white));

    //Social
    callbackManager = CallbackManager.Factory.create();

    MenuItem searchMenuItem = toolbar.getMenu().findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();
    UIHelper.setSearchViewStyle(searchView);
    UIHelper.changeSearchViewTextColor(searchView, Color.WHITE);

    slidingMenu = new SlidingMenu(this, toolbar);
}
 
Example #12
Source File: Login.java    From UberClone with MIT License 6 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 #13
Source File: LoginActivity.java    From social-app-android with 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 #14
Source File: LoginActivity.java    From social-app-android with 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 #15
Source File: AbsModuleFragment.java    From ONE-Unofficial with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(getLayoutId(), null);
    ButterKnife.bind(this, view);
    shareDialog = new ShareDialog(this);
    CallbackManager callbackManager = CallbackManager.Factory.create();
    shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {

        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {
            TextToast.shortShow(getString(R.string.share_fail));
        }
    });
    pager.setOnPageChangeListener(this);
    pager.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ViewPager>() {
        @Override
        public void onRefresh(PullToRefreshBase<ViewPager> refreshView) {
            refresh();
        }
    });
    adapter = new FragmentAdapter(getChildFragmentManager(), new ArrayList<AbsBaseFragment>());
    pager.setAdapter(adapter);
    init();
    instance=this;
    return view;
}
 
Example #16
Source File: FbLoginHiddenActivity.java    From SocialLoginManager with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  callbackManager = CallbackManager.Factory.create();
  LoginManager.getInstance().registerCallback(callbackManager, this);

  LoginManager.getInstance().logOut();

  if (SocialLoginManager.getInstance(this).isWithProfile()) {
    LoginManager.getInstance().logInWithReadPermissions(this, PERMISSIONS);
  } else {
    LoginManager.getInstance().logInWithReadPermissions(this, null);
  }
}
 
Example #17
Source File: ActivityModule.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@ActivityScope @Provides AccountNavigator provideAccountNavigator(
    @Named("main-fragment-navigator") FragmentNavigator fragmentNavigator,
    AptoideAccountManager accountManager, CallbackManager callbackManager,
    GoogleApiClient googleApiClient, AccountAnalytics accountAnalytics,
    BottomNavigationNavigator bottomNavigationNavigator, ThemeManager themeManager) {
  return new AccountNavigator(bottomNavigationNavigator, fragmentNavigator, accountManager,
      ((ActivityNavigator) activity), LoginManager.getInstance(), callbackManager,
      googleApiClient, PublishRelay.create(), "http://m.aptoide.com/account/password-recovery",
      accountAnalytics, themeManager);
}
 
Example #18
Source File: LoginInteractorImpl.java    From Saude-no-Mapa with MIT License 5 votes vote down vote up
@Override
public void requestLoginToFacebook(List<String> permissions, FacebookCallback<LoginResult> callback) {
    mCallbackmanager = CallbackManager.Factory.create();
    LoginManager.getInstance()
            .logInWithReadPermissions((LoginActivity) mContext, permissions);
    LoginManager.getInstance()
            .registerCallback(mCallbackmanager, callback);
}
 
Example #19
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //--------------------------------------------//
    FacebookSdk.sdkInitialize(this);//El SDK necesita ser inicializado antes de usar cualquiera de sus métodos,pasando el contexto de la actividad(Activity)
    callbackManager = CallbackManager.Factory.create();//inizializamos el CallbackManager
    //---------------------------------------------//
    setContentView(R.layout.activity_main);

    info = (TextView) findViewById(R.id.info);
    loginButton = (LoginButton) findViewById(R.id.login_button);
    //--------------------------------------------------//

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {//Si la autenticacion fue correcta
            info.setText("Login attempt success.");

        }

        @Override
        public void onCancel() {//Si se cancela la solicitus de login
            info.setText("Login attempt canceled.");
        }

        @Override
        public void onError(FacebookException e) {//Si ocurre un error
            info.setText("Login attempt failed.");
        }
    });
}
 
Example #20
Source File: LoginActivity.java    From Simple-Blog-App with MIT License 5 votes vote down vote up
private void fbInit() {

        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();
        LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                Log.d("facebook:token", AccessToken.getCurrentAccessToken().getToken());
                AccessToken.getCurrentAccessToken().getToken();
                signInWithFacebook(loginResult.getAccessToken());
            }

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

            @Override
            public void onError(FacebookException error) {
                Log.d(TAG, "facebook:onError", error);
            }
        });
        fbImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginManager.getInstance().logInWithReadPermissions(LoginActivity.this, Arrays.asList("email", "user_location", "user_birthday", "public_profile", "user_friends"));
            }
        });
    }
 
Example #21
Source File: LoginActivity.java    From android with MIT License 5 votes vote down vote up
private void setupFacebookLogin() {
    facebookCallbackManager = CallbackManager.Factory.create();

    vFacebookButton.setReadPermissions(getResources().getString(R.string.facebook_permissions));
    vFacebookButton.registerCallback(facebookCallbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            final String token = loginResult.getAccessToken().getToken();

            runSocialLoginTask(Const.ApiValues.OAUTH_TYPE_FACEBOOK, token);
        }

        @Override
        public void onCancel() {
        }

        @Override
        public void onError(FacebookException error) {
            try {
                final String message = String.format(
                        getResources().getString(R.string.snackbar_auth_error_facebook),
                        error.getMessage()
                );
                RedSnackbar.make(findViewById(R.id.root_view),
                        message,
                        Snackbar.LENGTH_LONG)
                        .show();
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
        }
    });

    vFacebookButton.setTypeface(TypefaceHelper.getTypeface(this, Const.TypeFaces.REGULAR));
}
 
Example #22
Source File: UserService.java    From Android-SDK with MIT License 5 votes vote down vote up
@Deprecated
public void loginWithFacebookSdk( android.app.Activity context, CallbackManager callbackManager, final
                                  AsyncCallback<BackendlessUser> responder, boolean stayLoggedIn  )
{
  AsyncCallback<BackendlessUser> internalResponder = getUserLoginAsyncHandler( responder, stayLoggedIn );
  getUserServiceAndroidExtra().loginWithFacebookSdk( context, callbackManager, internalResponder );
}
 
Example #23
Source File: UserService.java    From Android-SDK with MIT License 5 votes vote down vote up
@Deprecated
public void loginWithFacebookSdk( android.app.Activity context, final Map<String, String> facebookFieldsMappings,
                           final List<String> permissions, CallbackManager callbackManager, final
                                  AsyncCallback<BackendlessUser> responder, boolean stayLoggedIn )
{
  AsyncCallback<BackendlessUser> internalResponder = getUserLoginAsyncHandler( responder, stayLoggedIn );
  getUserServiceAndroidExtra().loginWithFacebookSdk( context, facebookFieldsMappings, permissions, callbackManager,
                                                     internalResponder );
}
 
Example #24
Source File: FBLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
public FBLoginInstance(Activity activity, final LoginListener listener,
                       final boolean fetchUserInfo) {
    super(activity, listener, fetchUserInfo);
    if (!FacebookSdk.isInitialized()) {
        FacebookSdk.setApplicationId(ShareManager.CONFIG.getFbClientId());
        FacebookSdk.sdkInitialize(activity.getApplicationContext());
        if (BuildConfig.DEBUG) {
            FacebookSdk.setIsDebugEnabled(true);
            FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
        }
    }

    callbackManager = CallbackManager.Factory.create();
}
 
Example #25
Source File: FacebookHelper.java    From AndroidBlueprints with Apache License 2.0 5 votes vote down vote up
/**
 * Sign in to google account - with Google's log in button.
 *
 * @param activity    the activity
 * @param callback    the callback to receive the method's result
 * @param loginButton the login button associated with this sign in
 */
public void signIn(@NonNull Activity activity, @NonNull final FacebookLoginResultCallback callback, @NonNull LoginButton loginButton) {
    mCallbackManager = CallbackManager.Factory.create();
    mFacebookLoginResultCallBack = callback;
    initLoginButton(activity, loginButton);
    registerCallBackManager(activity, loginButton);

}
 
Example #26
Source File: FacebookHelper.java    From AndroidBlueprints with Apache License 2.0 5 votes vote down vote up
/**
 * Sign in to google account - without Google's log in button.
 *
 * @param activity the activity
 * @param callback the callback to receive the method's result
 */
public void signIn(@NonNull Activity activity, @NonNull final FacebookLoginResultCallback callback) {
    mCallbackManager = CallbackManager.Factory.create();
    mFacebookLoginResultCallBack = callback;
    registerCallBackManager(activity);

    LoginManager.getInstance()
            .setLoginBehavior(LoginBehavior.NATIVE_WITH_FALLBACK)
            .logInWithPublishPermissions(activity, null);
}
 
Example #27
Source File: FacebookSignUpActivity.java    From socialmediasignup with MIT License 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    callbackManager = CallbackManager.Factory.create();

    LoginManager.getInstance().registerCallback(callbackManager, this);
    LoginManager.getInstance().logInWithReadPermissions(this, getScopes());
}
 
Example #28
Source File: FacebookDialogBase.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
@Override
public final void registerCallback(
        final CallbackManager callbackManager,
        final FacebookCallback<RESULT> callback) {
    if (!(callbackManager instanceof CallbackManagerImpl)) {
        throw new FacebookException("Unexpected CallbackManager, " +
                "please use the provided Factory.");
    }
    registerCallbackImpl((CallbackManagerImpl)callbackManager, callback);
}
 
Example #29
Source File: FacebookDialogBase.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
@Override
public final void registerCallback(
        final CallbackManager callbackManager,
        final FacebookCallback<RESULT> callback,
        final int requestCode) {
    setRequestCode(requestCode);
    registerCallback(callbackManager, callback);
}
 
Example #30
Source File: FacebookNetwork.java    From EasyLogin with MIT License 5 votes vote down vote up
public FacebookNetwork(Activity activity, List<String> permissions) {
    this.activity = new WeakReference<>(activity);
    callbackManager = CallbackManager.Factory.create();
    String applicationID = Utility.getMetadataApplicationId(this.activity.get());
    this.permissions = permissions;

    if (applicationID == null) {
        throw new IllegalStateException("applicationID can't be null\n" +
                "Please check https://developers.facebook.com/docs/android/getting-started/");
    }
}