Parse和Facebook SDK accessToken返回null

时间:2015-09-04 22:51:56

标签: facebook parse-platform graph

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

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);
    }

1 个答案:

答案 0 :(得分:0)

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

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

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