Search in sources :

Example 6 with LoginResult

use of com.facebook.login.LoginResult in project facebook-android-sdk by facebook.

the class HelloFacebookSampleActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            handlePendingAction();
            updateUI();
        }

        @Override
        public void onCancel() {
            if (pendingAction != PendingAction.NONE) {
                showAlert();
                pendingAction = PendingAction.NONE;
            }
            updateUI();
        }

        @Override
        public void onError(FacebookException exception) {
            if (pendingAction != PendingAction.NONE && exception instanceof FacebookAuthorizationException) {
                showAlert();
                pendingAction = PendingAction.NONE;
            }
            updateUI();
        }

        private void showAlert() {
            new AlertDialog.Builder(HelloFacebookSampleActivity.this).setTitle(R.string.cancelled).setMessage(R.string.permission_not_granted).setPositiveButton(R.string.ok, null).show();
        }
    });
    shareDialog = new ShareDialog(this);
    shareDialog.registerCallback(callbackManager, shareCallback);
    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }
    setContentView(R.layout.main);
    profileTracker = new ProfileTracker() {

        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
            updateUI();
            // It's possible that we were waiting for Profile to be populated in order to
            // post a status update.
            handlePendingAction();
        }
    };
    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);
    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            onClickPostStatusUpdate();
        }
    });
    postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    postPhotoButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            onClickPostPhoto();
        }
    });
    // Can we present the share dialog for regular links?
    canPresentShareDialog = ShareDialog.canShow(ShareLinkContent.class);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = ShareDialog.canShow(SharePhotoContent.class);
}
Also used : AlertDialog(android.app.AlertDialog) ShareLinkContent(com.facebook.share.model.ShareLinkContent) SharePhotoContent(com.facebook.share.model.SharePhotoContent) ShareDialog(com.facebook.share.widget.ShareDialog) LoginResult(com.facebook.login.LoginResult) View(android.view.View) ProfilePictureView(com.facebook.login.widget.ProfilePictureView) TextView(android.widget.TextView)

Example 7 with LoginResult

use of com.facebook.login.LoginResult in project react-native-fbsdk by facebook.

the class RCTLoginButton method init.

public void init() {
    mAccessTokenTracker = new AccessTokenTracker() {

        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            if (currentAccessToken == null) {
                WritableMap event = Arguments.createMap();
                event.putString("type", "logoutFinished");
                ReactContext context = (ReactContext) getContext();
                context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
            }
        }
    };
    this.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", null);
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", false);
            result.putArray("grantedPermissions", Arguments.fromJavaArgs(setToStringArray(loginResult.getRecentlyGrantedPermissions())));
            result.putArray("declinedPermissions", Arguments.fromJavaArgs(setToStringArray(loginResult.getRecentlyDeniedPermissions())));
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }

        @Override
        public void onError(FacebookException error) {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", error.toString());
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", false);
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }

        @Override
        public void onCancel() {
            WritableMap event = Arguments.createMap();
            event.putString("type", "loginFinished");
            event.putString("error", null);
            WritableMap result = Arguments.createMap();
            result.putBoolean("isCancelled", true);
            event.putMap("result", result);
            ReactContext context = (ReactContext) getContext();
            context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
        }
    });
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) WritableMap(com.facebook.react.bridge.WritableMap) ThemedReactContext(com.facebook.react.uimanager.ThemedReactContext) ReactContext(com.facebook.react.bridge.ReactContext) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult)

Example 8 with LoginResult

use of com.facebook.login.LoginResult in project RxFacebook by YouClap.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    callbackManager = CallbackManager.Factory.create();
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            List<String> perm = new ArrayList<>();
            perm.add("email");
            perm.add("public_profile");
            RxFacebookLogin.logInWithReadPermissions(perm).subscribe(new Consumer<LoginResult>() {

                @Override
                public void accept(@NonNull LoginResult loginResult) throws Exception {
                    Log.d(LOG_TAG, "accept " + loginResult.getAccessToken());
                }
            }, new Consumer<Throwable>() {

                @Override
                public void accept(@NonNull Throwable throwable) throws Exception {
                    Log.e(LOG_TAG, "error ", throwable);
                }
            }, new Action() {

                @Override
                public void run() throws Exception {
                    Log.e(LOG_TAG, "onCompleted");
                }
            });
        }
    });
}
Also used : Action(io.reactivex.functions.Action) Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) LoginResult(com.facebook.login.LoginResult) FloatingActionButton(android.support.design.widget.FloatingActionButton) ArrayList(java.util.ArrayList) List(java.util.List) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

LoginResult (com.facebook.login.LoginResult)8 FacebookException (com.facebook.FacebookException)5 View (android.view.View)4 TextView (android.widget.TextView)3 AccessToken (com.facebook.AccessToken)2 Profile (com.facebook.Profile)2 ProfileTracker (com.facebook.ProfileTracker)2 LoginButton (com.facebook.login.widget.LoginButton)2 ProfilePictureView (com.facebook.login.widget.ProfilePictureView)2 ShareDialog (com.facebook.share.widget.ShareDialog)2 AlertDialog (android.app.AlertDialog)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 Toolbar (android.support.v7.widget.Toolbar)1 Button (android.widget.Button)1 AccessTokenTracker (com.facebook.AccessTokenTracker)1 FacebookCallback (com.facebook.FacebookCallback)1 GraphRequest (com.facebook.GraphRequest)1 GraphResponse (com.facebook.GraphResponse)1