java - 在 facebook sdk 4.0+ 上获取可标记的 friend

标签 java android facebook facebook-graph-api

我的可标记 friend 列表有问题,这是我的代码,与旧的 sdk 一起工作得很好。

       public void getTaggableFriends(){
        Session activeSession = Session.getActiveSession();
        if(activeSession.getState().isOpened()){
        new Request(
                activeSession,
                "/me/taggable_friends",
                null,
                HttpMethod.GET,
                new Request.Callback() {
                    public void onCompleted(Response response) {

                        GraphObject graphObject = response.getGraphObject();
                        if (graphObject != null) {
                            JSONObject jsonObject = graphObject.getInnerJSONObject();
                            String taggableFriendsJson = jsonObject.toString();
                            Gson gson = new Gson();
                            TaggableFriendsWrapper taggableFriendsWrapper= gson.fromJson(taggableFriendsJson, TaggableFriendsWrapper.class);
                            ArrayList<TaggableFriends> invitableFriends = new ArrayList<TaggableFriends>();
                            invitableFriends = taggableFriendsWrapper.getData();
                            int i;
                            for(i = 0; i < invitableFriends.size(); i++)
                            {
                                try
                                {
                                MainActivity.myMenu.add(invitableFriends.get(i).getName());
                                }
                                catch(Exception e){}
                            }
                            MainActivity.myMenu.add("Tot: " + i);
                        }else {

                        }
                        //response.get

                    }
                }
            ).executeAsync();
        }
    }

言归正传,如何适配SDK 4.0?还是有其他方法可以做到这一点??我不知道从哪里开始,提前致谢。

最佳答案

你可以简单地把它改成

if(AccessToken.getCurrentAccessToken() != null)
{
    GraphRequest graphRequest = GraphRequest.newGraphPathRequest(
            AccessToken.getCurrentAccessToken(),
            "me/taggable_friends",
            new GraphRequest.Callback()
            {
                @Override
                public void onCompleted(GraphResponse graphResponse)
                {
                    //Your code

                    if(graphResponse != null)
                        {
                            JSONObject jsonObject = graphResponse.getJSONObject();
                            String taggableFriendsJson = jsonObject.toString();
                            Gson gson = new Gson();
                            TaggableFriendsWrapper taggableFriendsWrapper= gson.fromJson(taggableFriendsJson, TaggableFriendsWrapper.class);
                            ArrayList<TaggableFriends> invitableFriends = new ArrayList<TaggableFriends>();
                            invitableFriends = taggableFriendsWrapper.getData();
                            int i;
                            for(i = 0; i < invitableFriends.size(); i++)
                            {
                                try
                                {
                                    MainActivity.myMenu.add(invitableFriends.get(i).getName());
                                }
                                catch(Exception e){}
                            }
                            MainActivity.myMenu.add("Tot: " + i);
                        }else {

                        }
                        //response.get

                }
            }
        );

        Bundle parameters = new Bundle();
        parameters.putInt("limit", 5000); //5000 is maximum number of friends you can have on Facebook

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

关于java - 在 facebook sdk 4.0+ 上获取可标记的 friend ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31235297/

相关文章:

android - AlertDialog - CheckedTextView 不起作用

android - 手机上的文本缩放

机器可读格式的 Facebook API

Facebook Marketing Api错误: (#2635) You are calling a deprecated version of the Ads API.,请更新至最新版本: v3.2。”

java - 无法将 java.lang.Integer 转换为 int

java - 为什么我可以用公共(public)方法覆盖 protected 方法?

java - 如何使用 Java 在运行时缩小不同的 javascript 文件

android - 将 Ionic2 CLI 更新到 Ionic3 后,由于 facebook 插件,Cordova 构建失败

android - 如何从我的应用程序在 Facebook 中分享文本

java - 没有 main 函数的 cmd 中的执行方法