Android Facebook SDK 4.0 login with LoginManager -


i trying migrate login code of old application sdk 3.0 sdk 4.0. have implemented login using loginmanager, have custom login buttons.

the problem no response facebook api. no success, no error, no exception thrown whatsoever. code below:

    //global refs     //callbacks     private callbackmanager mcallbackmanager;     private facebookcallback<loginresult> mfacebookcallback;      private list<string> mpermissions = arrays.aslist("email");     private loginmanager mloginmgr;     private activity mactivity;      //........      //code inside method     facebooksdk.sdkinitialize(getapplicationcontext());      //perhaps bit excessive     facebooksdk.addloggingbehavior(loggingbehavior.graph_api_debug_info);     facebooksdk.addloggingbehavior(loggingbehavior.developer_errors);     facebooksdk.addloggingbehavior(loggingbehavior.include_access_tokens);     facebooksdk.addloggingbehavior(loggingbehavior.include_raw_responses);     facebooksdk.setapplicationid(mactivity.getstring(r.string.sample_fb_id));      //init callbacks     mfacebookcallback = new facebookcallback<loginresult>() {         @override         public void onsuccess(loginresult loginresult) {             log.v("loginactivity login", loginresult.tostring());             graphrequest request = graphrequest.newmerequest(loginresult.getaccesstoken(), new graphrequest.graphjsonobjectcallback() {                 @override                 public void oncompleted(jsonobject object, graphresponse response) {                     // application code                     log.v("loginactivity", response.tostring());                     try {                         string email = object.getstring("email");                         log.v("loginactivity", "obtained email: ", email);                     } catch (jsonexception e) {                         e.printstacktrace();                     }                 }             });             request.executeasync();         }         @override         public void oncancel() {             log.e("loginactivity", "facebook login canceled");         }          @override         public void onerror(facebookexception e) {             log.e("loginactivity", "facebook login failed error");         }     };     mcallbackmanager = callbackmanager.factory.create();     mloginmgr = loginmanager.getinstance();     mloginmgr.registercallback(mcallbackmanager, mfacebookcallback);     mloginmgr.loginwithreadpermissions(mactivity, mpermissions); 

using debugger, able see line: mloginmgr.loginwithreadpermissions(mactivity, mpermissions); gets executed, none of callbacks ever triggered. have no errors in console, , device screen goes black , nothing happens.

i don't think matters, code executed in wrapper class (outside activity). tried inside activity, made no difference.

any suggestions? appreciated.

edit:

this declared inside androidmanifest.xml:

<activity android:name="com.facebook.facebookactivity"           android:theme="@android:style/theme.translucent.notitlebar"           android:configchanges="keyboard|keyboardhidden|screenlayout|screensize|orientation"           android:label="@string/app_name" /> 

if code in fragment, not use mactivity variable activity context.

to do:

  1. add line:

     callbackmanager.onactivityresult(requestcode, resultcode, data); in onactivityresult(, , , ) in fragment. 
  2. call:

     loginmanager.getinstance().loginwithreadpermissions(**this**, arrays.aslist("public_profile", "user_friends"));  

use this, not use this.getactivity()

  1. sure, done.

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -