简体   繁体   English

Android通过SDK 3.0获取Facebook朋友列表

[英]Android Getting Facebook friend list with SDK 3.0

I'm trying all day to get all my Facebook friend list using Facebook SDK 3.0 I don't want to use the FriendPickerFragment, since i don't want to display a picker, i want to create my own list of friends (displaying the name and image). 我整天都在尝试使用Facebook SDK 3.0获取我所有的Facebook朋友列表。我不想使用FriendPickerFragment,因为我不想显示选择器,所以我想创建自己的朋友列表(显示名称和图片)。

According to this post Facebook friends list returns empty this is possible only if a friend approves your app, but even when i tried this with my wife's account and mine, i'm still not able to get the friend list. 根据这篇文章, Facebook朋友列表返回空值,只有在朋友批准您的应用程序的情况下才有可能,但是即使我用妻子的帐户和我的账号尝试了此操作,我仍然无法获取朋友列表。

any help will be highly appreciated, I've spend so much time on this and reach a dead lock. 任何帮助将不胜感激,我花了很多时间在此上,陷入僵局。

Thanks! 谢谢!

Precondition: 前提:
1. Create an app on facebook. 1.在Facebook上创建一个应用。
2. Add hash code of android app into facebook app. 2.将android应用的哈希码添加到facebook应用中。

Android app: Android应用程式:
get permission (on your fb account who created fb app) 获得许可(在创建fb应用程序的fb帐户上)

authButton.setReadPermissions(Arrays.asList("basic_info, user_friends"));

authButton is com.facebook.widget.LoginButton (you can refer sample apps to find out how the login button works) authButton是com.facebook.widget.LoginButton(您可以参考示例应用程序以了解登录按钮的工作方式)

Method to get friend list: 获取好友列表的方法:

   Request r = new Request(session, "/me/friends", null,HttpMethod.GET, new Request.Callback() {
                        @Override
                        public void onCompleted(Response response) {
                            try {
                                GraphObject graphObj = response.getGraphObject();
                                if(graphObj != null){
                                    ArrayList<FBFriend> friendArrayList = new ArrayList<FBFriend>();
                                    JSONObject jsonObj = graphObj.getInnerJSONObject();
                                    JSONArray array = jsonObj.getJSONArray(DATA_NODE);
                                    for(int i = 0; i < array.length(); i++){
                                        JSONObject Jobj = (JSONObject)array.get(i);
                                        String id = Jobj.getString(FBFriend.ID_NOTE);
                                        String name = Jobj.getString(FBFriend.NAME_NOTE);
                                        FBFriend f = new FBFriend(id, name);
                                        friendArrayList.add(f);
                                    }
                                }
                            }
                        }
                    });
r.executeAsync()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM