如何在android中获得facebook用户生日?

时间:2014-02-04 02:27:13

标签: android facebook

我使用此代码获取Facebook用户信息。大多数信息都显示出来,但我需要的是用户生日。 json数组中没有用户生日。源代码为here.获取用户信息代码

  public void getProfileInformation() {
    mAsyncRunner.request("me", new RequestListener() {
        @Override
        public void onComplete(String response, Object state) {
            Log.d("Profile", response);
            String json = response;
            try {
                // Facebook Profile JSON data
                JSONObject profile = new JSONObject(json);
                Log.i("profile",profile+"");
                // getting name of the user
                final String name = profile.getString("name");

                // getting email of the user
                final String email = profile.getString("email");

                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Name: " + name + "\nEmail: " + email, Toast.LENGTH_LONG).show();
                    }

                });


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

        @Override
        public void onIOException(IOException e, Object state) {
        }

        @Override
        public void onFileNotFoundException(FileNotFoundException e,
                Object state) {
        }

        @Override
        public void onMalformedURLException(MalformedURLException e,
                Object state) {
        }

        @Override
        public void onFacebookError(FacebookError e, Object state) {
        }
    });
}

我需要一些建议。请!

 02-03 21:29:35.700: D/Profile(1350): {"id":"1550015884","name":"Aung Htoon Kyaw","first_name":"Aung","middle_name":"Htoon","last_name":"Kyaw","link":"https:\/\/www.facebook.com\/aung.htoonkyaw","hometown":{"id":"105988982772786","name":"Yangon, Burma"},"location":{"id":"115804185098639","name":"Rangoon, Yangon, Burma"},"work":[{"employer":{"id":"107622942602570","name":"KMMGroup"}}],"favorite_athletes":[{"id":"450149851675417","name":"Gohan Kazuto Uzumaki"},{"id":"339211762793623","name":"Natsu Dragneel"},{"id":"1347550405383513","name":"Instagram Girls"},{"id":"331817313532412","name":"Hinata Hyuga"},{"id":"481643341874600","name":"Erza Scarlet"},{"id":"123163411183595","name":"Sanji"}],"education":[{"school":{"id":"109294362421667","name":"BEST High School"},"year":{"id":"140617569303679","name":"2007"},"type":"High School"},{"school":{"id":"104056766297330","name":"University of Computer Studies, Yangon"},"year":{"id":"141778012509913","name":"2008"},"type":"College","with":[{"id":"1059125424","name":"Nara ChannLynn"}]},{"school":{"id":"106398082730475","name":"UCSY"},"year":{"id":"141778012509913","name":"2008"},"type":"College"}],"gender":"male","email":"waptan22\u0040gmail.com","timezone":6.5,"locale":"en_US","verified":true,"updated_time":"2013-09-12T14:32:54+0000","username":"aung.htoonkyaw"}

这是logcat输出。

1 个答案:

答案 0 :(得分:3)

要获取更多个人详细信息,您需要获得用户权限,因此您需要在会话中添加权限并提示用户接受/拒绝此权限。

如果您正在关注Androidhive教程,我担心它是旧的Facebook SKD,因此您需要阅读新版本的SDK,以解决您的问题,请检查page out特别是第2步

在添加权限代码的代码段上:

authButton.setReadPermissions(Arrays.asList("user_location", "user_birthday", "user_likes"));
...