我正在尝试为 android 设置 facebook 登录。我已经按照网上的所有文档来完成这项工作,我的主要参考资料是this。
我的代码中没有任何“错误”,但什么也没有出现,而且我确实感觉如果出现任何事情实际上不会发生任何事情。让我告诉你更好地理解:
管理FacebookFragment
public class ManageFacebookFragment extends Fragment {
final static String ARG_POSITION = "position";
int mCurrentPosition = -1;
private static final String TAG = MainScreenFragmentPagerAdapter.class.getSimpleName();
private UiLifecycleHelper uiHelper;
private final List<String> permissions;
public ManageFacebookFragment() {
permissions = Arrays.asList("user_status");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Getting the arguments to the Bundle object */
final Bundle data = getArguments();
/** Getting integer data of the key current_page from the bundle */
mCurrentPosition = data.getInt("current_page", 0);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.settings_accounts_facebook, container,
false);
LoginButton authButton = (LoginButton) v.findViewById(R.id.authButton);
// authButton.setFragment(this);
authButton.setReadPermissions(permissions);
return v;
}
@Override
public void onResume() {
super.onResume();
// For scenarios where the main activity is launched and user
// session is not null, the session state change notification
// may not be triggered. Trigger it if it's open/closed.
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
private final Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
}
settings_accounts_facebook.xml
<com.facebook.widget.LoginButton
android:id="@+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
/>
基本上我所拥有的只是我希望能够按下以让用户通过 facebook 进行身份验证的按钮......现在当我运行应用程序时它只是一个空白屏幕......我想知道这是否与facebook登录的片段实现,不确定。任何想法或建议将不胜感激。非常感谢!
安迪