Reputation: 14454
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 :)
Upvotes: 1
Views: 3944
Reputation: 14454
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 :/
Upvotes: 4
Reputation: 15662
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/
Upvotes: 0