Facebook的图形请求返回null

时间:2016-12-05 11:36:58

标签: android facebook-graph-api

我有一个Android应用程序,允许用户使用他们的登录按钮登录Facebook。我已经为loginButton设置了以下权限:

loginButton.setReadPermissions(
             "public_profile","user_birthday","user_location");

登录工作正常,但我想要做的是基本上获得一些关于他们的生日和实际位置的额外信息,以便创建一个新的用户"对象并以这种方式将其写入我的数据库:

Bundle parameters = new Bundle();         parameters.putString(" fields"," id,first_name,last_name,gender,birthday,link,location");         最终用户newUser = new User();

    GraphRequest request = GraphRequest.newMeRequest(
            loginResult.getAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    Log.i("***LoginResponse :",response.toString());

                    try {

                         String userGender = response.getJSONObject().getString("gender");
                         String firstName = response.getJSONObject().getString("first_name");
                         String lastName = response.getJSONObject().getString("last_name");
                         String facebookProfileLink = response.getJSONObject().getString("link");

                         String userBirthdate = response.getJSONObject().getString("birthday");

                        String userCity = response.getJSONObject().getJSONObject("location").getString("name");


                        Profile profile = Profile.getCurrentProfile();
                        String id = profile.getId();
                        String link = profile.getLinkUri().toString();
                        Uri profilePicture = profile.getProfilePictureUri(200,200);
                        Log.i("Link",link);


                        newUser.setUserAge(userBirthdate);
                        Log.i("****Login" + "UserBirthday", userBirthdate);

                        newUser.setUserEmail("default@facebook.com");
                        newUser.setUserGender(genderFixer(userGender));


                        newUser.setUserCity(userCity);
                        Log.i("****Login" + "UserCity", userCity);

                        newUser.setFacebookProfile(facebookProfileLink);
                        newUser.setUserName(firstName);
                        newUser.setUserSurname(lastName);
                        newUser.setProfileImage(profilePicture.toString());


                        String userId = mAuth.getCurrentUser().getUid();
                        mDatabaseReference.child(userId).setValue(newUser);

                        if (Profile.getCurrentProfile()!=null)
                        {
                            Log.i("Login", "ProfilePic" + Profile.getCurrentProfile().getProfilePictureUri(200, 200));
                        }


                        Log.i("****Login"+ "FirstName", firstName);
                        Log.i("****Login" + "LastName", lastName);
                        Log.i("****Login" + "Gender", userGender);



                    }catch (JSONException e) {
                        e.printStackTrace();
                    }


                }
            }
    );
    request.setParameters(parameters);
    request.executeAsync();

}

我可以阅读所有数据,但不能"生日"和"位置" - > "名称&#34 ;. 注意:我完全清楚这些字段可能是空的,我知道如何处理它,但我正在使用在Facebook个人资料中实际拥有这些字段的帐户进行测试。这是我得到的回应:

I/***LoginResponse :: {Response:  responseCode: 200, 
   graphObject: {
"id":"116293545526048",           
"first_name":"Davide",
"last_name":"Harlee",
"gender":"male",
"link":"https:\/\/www.facebook.com\/app_scoped_user_id\/116293545526048\/"},          error: null} 

这只发生在我使用我的"真实" Facebook帐户我得到了我需要的所有信息,没有问题获得位置和生日就好了

0 个答案:

没有答案