java - Facebook 4.x Login SDK Not Completing Login Process -
i following tutorial , working, when click on login button, progress spinner appears brief moment, disappears. have tried debug, , i'm not hitting callback:
private facebookcallback<loginresult> callback = new facebookcallback<loginresult>() { @override public void onsuccess(loginresult loginresult) { accesstoken accesstoken = loginresult.getaccesstoken(); profile profile = profile.getcurrentprofile(); displaymessage(profile); } @override public void oncancel() { } @override public void onerror(facebookexception e) { } };
here complete code:
import android.content.intent; import android.support.v4.app.fragment; import android.os.bundle; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.textview; import com.facebook.accesstoken; import com.facebook.accesstokentracker; import com.facebook.callbackmanager; import com.facebook.facebookcallback; import com.facebook.facebookexception; import com.facebook.facebooksdk; import com.facebook.profile; import com.facebook.profiletracker; import com.facebook.login.loginresult; import com.facebook.login.widget.loginbutton; import static com.facebook.facebooksdk.getapplicationcontext; /** * placeholder fragment containing simple view. */ public class mainactivityfragment extends fragment { private callbackmanager callbackmanager; private textview displayname; private accesstokentracker accesstokentracker; private profiletracker profiletracker; private facebookcallback<loginresult> callback = new facebookcallback<loginresult>() { @override public void onsuccess(loginresult loginresult) { accesstoken accesstoken = loginresult.getaccesstoken(); profile profile = profile.getcurrentprofile(); displaymessage(profile); } @override public void oncancel() { } @override public void onerror(facebookexception e) { } }; public mainactivityfragment() { } @override public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); facebooksdk.sdkinitialize(getactivity().getapplicationcontext()); callbackmanager = callbackmanager.factory.create(); accesstokentracker = new accesstokentracker() { @override protected void oncurrentaccesstokenchanged(accesstoken accesstoken, accesstoken accesstoken1) { } }; profiletracker = new profiletracker() { @override protected void oncurrentprofilechanged(profile oldprofile, profile newprofile) { displaymessage(newprofile); } }; accesstokentracker.starttracking(); profiletracker.starttracking(); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_main, container, false); } @override public void onviewcreated(view view, bundle savedinstancestate){ super.onviewcreated(view, savedinstancestate); loginbutton loginbutton = (loginbutton) view.findviewbyid(r.id.login_button); displayname = (textview) view.findviewbyid(r.id.displayname); loginbutton.setreadpermissions("user_friends"); loginbutton.setfragment(this); loginbutton.registercallback(callbackmanager, callback); } @override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); callbackmanager.onactivityresult(requestcode, resultcode, data); } private void displaymessage(profile profile){ if(profile != null){ displayname.settext(profile.getname()); } } @override public void onstop() { super.onstop(); accesstokentracker.stoptracking(); profiletracker.stoptracking(); } @override public void onresume() { super.onresume(); profile profile = profile.getcurrentprofile(); displaymessage(profile); } }
it turns out issues caused not having uses-permission
in right place. don't know why allow app work once or twice, did. had make manifest like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="my.app" > <uses-permission android:name="android.permission.internet"/> <application ....
before, looked like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="my.app" > <application .... <uses-permission android:name="android.permission.internet"/>
Comments
Post a Comment