android - error in login with facebook login -
i'm trying implement login facebook in application. have imported sdk , set right settings on developer account on facebook. when try login facebook redirects me right loginactivity instead of mainactivity.
the facebook button imported in xml file this:
<com.facebook.login.widget.loginbutton android:id="@+id/fb_login_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_margintop="30dp" android:layout_marginbottom="30dp" />
this launch activitys oncreate function looks like:
facebooksdk.sdkinitialize(this); callbackmanager = callbackmanager.factory.create(); loginmanager.getinstance().registercallback(callbackmanager, new facebookcallback<loginresult>() { @override public void onsuccess(loginresult loginresult) { // user logged in // create login session session.setlogin(true); // launch main activity intent intent = new intent(loginactivity.this, mainactivity.class); startactivity(intent); finish(); } @override public void oncancel() { toast.maketext(getapplicationcontext(), "you cancelled while logging in, please login gain access.", toast.length_short).show(); } @override public void onerror(facebookexception exception) { toast.maketext(getapplicationcontext(), "an error appeared, please try again.", toast.length_short).show(); } }); setcontentview(r.layout.activity_login);
when click facebook login button redirected facebook app , when log in facebook app asks permission, redirected login activity.
i found problem was. forgot line of code initiates action after you're logged in, is:
loginmanager.getinstance().loginwithreadpermissions(this, arrays.aslist("public_profile", "user_friends", "email"));
you should enter after you've set behaviour of loginmanager.
Comments
Post a Comment