我正在开发需要 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 应用程序的设备上进行测试。
谢谢 :)