1

我正在开发需要 facebook 登录才能发布 facebook 评论的 android 应用程序。但是我一直无法登录。所以我按照https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/上的教程进行操作,但我得到了 state.isCloced() == true登录后(facebook登录按钮也不会更改它的注销文本)。我看不出它不起作用的任何原因。谁能帮我?

参考教程我有片段:

<?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>

在我的 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);
}

单击LoginButton后,弹出fb权限对话框,单击确定,然后看到圆形进度条,然后再次看到登录按钮。在 LogCat 中,状态仍然是关闭的 :(

难道我做错了什么?或者可能是因为带有 loginButton 的 Fragment 嵌套在另一个 Fragment 中?

我正在安装了 android 4、本机 FB 应用程序的设备上进行测试。

谢谢 :)

4

2 回答 2

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 :/

于 2013-03-09T12:14:04.527 回答
0

如果您在片段中使用 LoginButton,则需要从包含片段中调用 loginButton.setFragment,并覆盖该片段中的 onActivityResult 方法。

请参阅此处的教程https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/

于 2013-03-06T19:51:54.927 回答