简体   繁体   English

当我尝试使用facebook sdk登录我的Android应用程序时,我一直得到一个空用户和一个空错误。 我不知道为什么

[英]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.

相关问题 ADT函数不断返回null,我不知道为什么 - ADT function keeps returning null and i have NO clue why 为什么我的Android代码中出现空指针错误? - Why am I getting a null pointer error in my Android Code? 为什么当我尝试访问我的字符串数组时会得到“null”? - Why am I getting 'null' when I try to access my String Array? 为什么在所有任务完成执行后我都会继续获取空值 - Why do I keep getting null values when all tasks have finished execution 尝试将包从我的活动传递到我的片段时,为什么我不断收到 null? - Why do I keep getting null when trying to pass a bundle from my activity to my fragment? 尝试发送到服务器时,为什么我的吸气剂返回null? - Why are my getters returning null when I try to send to the server? 为什么我不断收到此空指针未知源错误? - Why do I keep getting this null pointer unknown source error? 当我尝试使用电话和密码登录我的服务器应用程序时,它显示“用户在数据库中不存在”,我的数据库在firebase中 - When i try to login in my server app with Phone and password it show “User does not exist in Database” I have my Database in firebase 将元素绑定到代码后,为什么我的代码总是收到空指针异常? 我在Android Studio中使用Java - Why is my code always receiving a null pointer exception when I have binded the element in to it? I am using Java in Android Studio 我不断收到错误,位置是 null - i keep getting an error that location is null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM