简体   繁体   English

在 facebook sdk 4.0+ 上获得可标记的朋友

[英]get taggable friends on facebook sdk 4.0+

I have a problem with the list of taggable friends, this is my code , that with the old sdk worked great.我的可标记朋友列表有问题,这是我的代码,使用旧的 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();
        }
    }

get to the point , how can I adapt SDK 4.0 ?切入正题,我如何适应 SDK 4.0? Or is there some other way to do this ??或者有没有其他方法可以做到这一点? I would not know where to start, thanks in advance.我不知道从哪里开始,提前致谢。

You can simply change it to您可以简单地将其更改为

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

Now it wont work现在它行不通了

As of facebook doc the User Taggable Friend node was deprecated on April 4th, 2018 and now returns an empty data set.截至 facebook 文档,User Taggable Friend 节点已于 2018 年 4 月 4 日弃用,现在返回一个空数据集。

https://developers.facebook.com/docs/graph-api/reference/user-taggable-friend/ https://developers.facebook.com/docs/graph-api/reference/user-taggable-friend/

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

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