[英]When I try using the facebook sdk to login in my android app, I keep getting a null user and a null error. I have no clue why
I have double checked to make sure the app ids are the same. 我已经仔细检查以确保应用ID是相同的。 I don't know what could possibly be causing this.
我不知道是什么原因造成的。 I can post code snippets if you would like, but I basically followed the docs on setting up Facebook with Parse.
如果您愿意,我可以发布代码片段,但我基本上遵循了使用Parse设置Facebook的文档。
Here is a small snippet of my code: 这是我的代码的一小部分:
facebookLogInButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
List<String> permissions = Arrays.asList(Permissions.User.EMAIL);
ParseFacebookUtils.logIn(permissions, getActivity(), new LogInCallback() {
@Override
public void done(ParseUser user, ParseException e) {
if (user != null) {//if user exists
ParseUser currentUser = ParseUser.getCurrentUser();//get user
userDisplay.setText(currentUser.getString("username"));//set username to textedit
} else {
userDisplay.setText(e.getMessage());//print the error
}
}
});
}
});
Currently it crashes due to a null pointer error when trying to get the error message (in the else statement). 目前,在尝试获取错误消息时(在else语句中)由于空指针错误而崩溃。 So, not only is it failing the login process, I have a feeling that for some reason, it is not being initialized properly.
因此,不仅登录过程失败,我还是觉得由于某种原因,它没有被正确初始化。
I have initialized Facebook in my application class like so: 我在我的应用程序类中初始化了Facebook,如下所示:
ParseFacebookUtils.initialize(getResources().getString(R.string.facebook_app_id));
Thanks in advance. 提前致谢。
Figured out the answer: 想出答案:
I had initially had the onActivityResult inside my LogInFragment.java. 我最初在我的LogInFragment.java中有onActivityResult。 Instead I needed to put it inside the Activity that held the fragment.
相反,我需要把它放在持有片段的Activity里面。
So, put this: 所以,把这个:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ParseFacebookUtils.finishAuthentication(requestCode, resultCode, data);
}
inside the activity (NOT the fragment) where the login is happening. 在登录发生的活动(不是片段)内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.