mardi 7 avril 2015

Android Facebook SDK 4 login - no callbacks being called


Vote count:

0




I'm implementing facebook sdk 4.0 login/logout flow in an app and having trouble with the callbacks. The implementation takes place in a custom class (i.e. it neither implements activity nor fragment) but it receives a reference to its parent activity when it initializes. Here is the code in the constructor:



private CallbackManager callbackManager;


@Override
public void login(Activity parentActivity) {

callbackManager = CallbackManager.Factory.create();
final List<String> READ_PERMISSIONS = Collections.singletonList("some_permission_that_I_need");

LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {

Log.d("Facebook", "onSuccess with " + loginResult.getAccessToken().toString());

}

@Override
public void onCancel() {
Log.d("Facebook", "onCancel");
}

@Override
public void onError(FacebookException error) {
Log.d("Facebook", "onError");
error.printStackTrace();
}
});

AccessTokenTracker accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) {

Log.d("Facebook","access token tracker");

}
};

accessTokenTracker.startTracking();

if (AccessToken.getCurrentAccessToken() == null) {

Log.d("Facebook", "Accesstoken was null");

LoginManager.getInstance().logInWithReadPermissions(parentActivity, READ_PERMISSIONS);

}

}


I can see in the logs that the accesstoken was null and that therefore the method loginWithReadPermissions is being called.. but after that nothing. None of the callback methods are being called for the login flow. I tried moving the callback definition to the parent activity but I still get nothing back after calling loginWithReadPermissions. What am I missing here?



asked 53 secs ago

Jon

189






Android Facebook SDK 4 login - no callbacks being called

Aucun commentaire:

Enregistrer un commentaire