解析和 Facebook SDK accessToken 返回 null

问题描述 投票:0回答:1

我正在尝试使用 Facebook Graph Api 和 Parse API 来提取信息。调用Graph API时,GraphRepsone为null。问题是因为 accessToken 为空,但在尝试了许多不同的方法后我无法弄清楚如何修复。

buttonSignUpWithFacebook.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                // this is where you can begin doing facebook sign up process


                Log.i(TAG, "did click on facebook button");

                List<String> permissions = Arrays.asList("user_location", "user_friends", "email", "public_profile");

                ParseFacebookUtils.logInWithReadPermissionsInBackground(SignUpActivity.this, permissions, new LogInCallback() {
                    @Override
                    public void done(ParseUser user, ParseException err) {

                        if (user == null) {
                            Log.d("App", "Uh oh. The user cancelled the Facebook login.");
                        } else if (user.isNew()) {
                            Log.d("App", "User signed up and logged in through Facebook!");
                            startActivity(new Intent(SignUpActivity.this, Home.class));

                        } else {
                            Log.d("App", "User logged in through Facebook!");
                            setupUser();
                            startActivity(new Intent(SignUpActivity.this, Home.class));
                        }

                    }

                    public void setupUser() {
                        accessToken = AccessToken.getCurrentAccessToken();
                    }
                });




            GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    if (response != null) {
                        try {
                            String email = object.getString("email");
                            String firstName = object.getString("first_name");
                            Log.d(TAG, "first name  " + firstName);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
//                        String firstName = jsonResponseObject.getFirstName();
//                        String lastName = jsonResponseObject.getLastName();
                    }
                }
            });
            Bundle param = new Bundle();
            param.putString("fields","cover, birthday, email, first_name, last_name, ");
            request.setParameters(param);
            request.executeAsync();
        }

        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
    }
facebook parse-platform facebook-android-sdk
1个回答
0
投票

我不想给出一个模糊的答案,但我不认为问题出在代码片段中。我建议您修改步骤并确保再次完全遵循这些链接:

https://developers.facebook.com/docs/android/getting-started

https://parse.com/docs/android/guide#users-facebook-users

© www.soinside.com 2019 - 2024. All rights reserved.