Tomasz Ksepka
Tomasz Ksepka

Reputation: 37

Parse and Facebook SDK accessToken return null

I'm trying to extract information using the Facebook Graph Api along with Parse API. When calling the Graph API, The GraphRepsone is null. The problem is because the accessToken is null but I can't figure out how to fix after trying many different ways.

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

Upvotes: 0

Views: 182

Answers (1)

hhyder
hhyder

Reputation: 61

I'd hate to give a vague answer, but I don't think the problem is in the code snippet. I suggest you revise your steps and make sure you followed these links completely again:

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

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

Upvotes: 0

Related Questions