我正在尝试使用 Facebook 3.0 中的片段登录。我在片段中创建了一个图像按钮,它响应点击方法,如下所示:
OnCreateView 和 OnClickView 代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved){
View v = inflater.inflate(R.layout.mefrag, group, false);
ImageButton button = (ImageButton) v.findViewById(R.id.facebooklogin);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loginToFacebook();
}
});
return v;
}
logintoFacebook 方法不会启动下一个活动。它只显示 fb 对话框,接受我的详细信息,然后再次显示片段。我在一个单独的活动中测试了这段代码,它工作正常,我只是不知道为什么它在这里不起作用。
脸书登录代码:
公共无效 loginToFacebook(){
Session.openActiveSession(getActivity(), true, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Log.d("LOGIN", "activated session");
// make request to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
Log.d("LOGIN", "activated on complete");
fbuserid = user.getId();
fbusername = user.getFirstName();
SharedPreferences fbDetails = getActivity().
getSharedPreferences("fbDetails", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = fbDetails.edit();
editor.putString(FB_USER, user.getFirstName());
editor.putString(FB_ID,user.getId());
editor.putBoolean("logged in", true);
editor.commit();
loginFacebookKinveyUser();
Intent i = new
Intent("com.example.chartviewer.MyArtistsActivity");
startActivityForResult(i, 1);
}
}
});
}
}
});
}
有什么想法吗?