1

I'm developing android app which require facebook login for posting facebook comments. However I've got stuck on logging in. So I followed tutorial at https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/ but I'm getting state.isCloced() == true after log in (facebook login button also does not change it's text to log out). I don't see any reason why it is not working. Can anyone help me?

Reffering to tutorial I have fragment:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
<com.facebook.widget.LoginButton
    android:id="@+id/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginBottom="30dp"
    android:layout_marginTop="30dp" />
</LinearLayout>

And in my MainActivity:

    private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception)                 {
        onSessionStateChange(session, state, exception);
    }
};

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
}



private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (state.isOpened()) {
        Log.i("FacebookFragment", "State is opened");
    } else if (state.isClosed()) {
        Log.i("FacebookFragment", "State is closed");
    }
}

@Override
public void onResume() {
    super.onResume();
    uiHelper.onResume();
}

@Override
public void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}

@Override
public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}

After I click LoginButton, fb permission dialog pops up, I click ok, then I see round progress bar and then I see login button again. In LogCat is still State is closed :(

Am I doing something wrong? Or could it be because Fragment with loginButton is nested in another fragment?

I'm testing on device with android 4, native FB app installed.

Thanks :)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
bakua
  • 13,704
  • 7
  • 43
  • 62

2 Answers2

4

Ok I solved it, based on "remote_app_id does not match stored id" exception i found answer https://stackoverflow.com/a/14421260/1618316 and printed facebook app id. First I generated app id with command from fb tutorial, but it was different to one printed by answer above. So I put new key at fb and now it works.

But I still wonder how is possible that command from tutorial gave me wrong hash :/

Community
  • 1
  • 1
bakua
  • 13,704
  • 7
  • 43
  • 62
0

If you're using the LoginButton inside a fragment, then you need to call loginButton.setFragment from the containing fragment, and also override the onActivityResult method inside that fragment.

See the tutorial here https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/

Ming Li
  • 15,672
  • 3
  • 37
  • 35
  • But that is only if I want fragment to manage those methods isn't it? Otherwise I can manage those calls in my activity (?) – bakua Mar 06 '13 at 22:07
  • actually, can you print out the exception field AND the actual state as well? If your status callback is being called, then the state is transitioning, and there may have been an error. – Ming Li Mar 07 '13 at 17:41
  • Hello, thanks for responding :) Login process is not throwing any exceptions for me (or do you mean somenthing else?). I will give you actual state in two days because I am not currently in city. Regards bakua. – bakua Mar 07 '13 at 18:21