我们正在使用我们的 android 应用程序 Facebook SDK 版本 3.0.1 对于 Facebook 登录,我使用了本教程: https ://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/
我的许多用户在使用 Facebook 登录进入我们的应用程序时遇到问题。用户不断向我发送有关此问题的电子邮件,我也可以在他们的日志中看到他们无法进入。单击 Facebook LoginButton 后,它会转到 Facebook LoginActivity,显示进度条并永远停留在那里。我没有从 Facebook 得到任何答复,也没有任何异常,除非用户单击后退按钮。
我已经从 Facebook 的 SDK 打印了一些日志,所以也许有人会理解为什么会出现这个问题。
这是一个可以正常工作的日志流示例
这是我的代码:
我的活动:
/**My Activity **/
//BackClickListenerActivity extends FragmentActivity
public class RegisterActivity extends BackClickListenerActivity implements RegistrationManager{
private RegistrationFragment mainFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
if (savedInstanceState == null) {
// Add the fragment on initial activity setup
mainFragment = new RegistrationFragment();
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, mainFragment)
.commit();
} else {
// Or set the fragment from restored state info
mainFragment = (RegistrationFragment) getSupportFragmentManager()
.findFragmentById(android.R.id.content);
}
...
}
public void onStart() {
mainFragment.initialize(this,R.layout.register,false);
super.onStart();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_FACEBOOK_LOGIN:
if (resultCode == RESULT_OK) {
...
}
else {
...
}
...
}
}
}
我的片段:
public class RegistrationFragment extends Fragment{
public void initialize(RegistrationManager registrationManager, int layoutRes, boolean hideButton){
this.registrationManager = registrationManager;
sentRequest = false;
// I use this fragment from 2 different Activities, and 2 layouts
this.layoutRes = layoutRes;
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
Log.d(TAG,"onCreateView RegistrationManager");
final View view = inflater.inflate(layoutRes, container, false);
LoginButton authButton = (LoginButton) view.findViewById(R.id.facebook_login);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList(FacebookConfig.getInstance().getPermissions()));
...
}
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG,"onCreate RegistrationManager");
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if(state == SessionState.OPENING){
...
}
else if (state.isOpened()) {
...
} else if (state.isClosed()) {
...
}
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onResume() {
super.onResume();
uiHelper.onResume();
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onStop(){
super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
}
在 SDK 中,我做了一些处理 LoginButton 的更改 - 我更改了图像、文本并在 onClick 侦听器的注释下放置会话不为空的情况(以防止注销)。希望我的问题足够清楚,有人可以帮助我们。谢谢你,亚历克斯