android [已关闭][已关闭]

acruukt9  于 2023-05-21  发布在  Android
关注(0)|答案(1)|浏览(138)

已关闭,此问题为opinion-based。目前不接受答复。
**想改善这个问题吗?**更新问题,以便editing this post可以用事实和引用来回答。

2天前关闭。
Improve this question
如何改进此代码?

使用gson解析Facebook GraphObject

我是在Facebook上工作的可标记的朋友,我已经解析了GraphObject,可能对别人有帮助。

解析可标记好友函数::需要用户朋友权限

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

                    }else {
                        // do something
                    }
                    //response.get
                    
                }
            }
        ).executeAsync();
    }
}

TaggableFriendsWrapper.java

public class TaggableFriendsWrapper {
    
    private ArrayList<TaggableFriends> data;
    private Paging paging;
    
    public ArrayList<TaggableFriends> getData() {
        return data;
    }

    public void setData(ArrayList<TaggableFriends> data) {
        this.data = data;
    }
    
    public Paging getPaging() {
        return paging;
    }

    public void setPaging(Paging paging) {
        this.paging = paging;
    }

    public class Paging {
        
        private Cursors cursors;
        public Cursors getCursors() {
            return cursors;
        }

        public void setCursors(Cursors cursors) {
            this.cursors = cursors;
        }
    }
    
    public class Cursors {
        private String after;
        private String before;
        
        public String getAfter() {
            return after;
        }
        public void setAfter(String after) {
            this.after = after;
        }
        public String getBefore() {
            return before;
        }
        public void setBefore(String before) {
            this.before = before;
        }
        
    }
    
}

TaggableFriends.java

public class TaggableFriends {
    
    private String id;
    private String name;
    private Picture picture;
    
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    
    public Picture getPicture() {
        return picture;
    }
    public void setPicture(Picture picture) {
        this.picture = picture;
    }

    public class Picture {
        
        private Data data;

        public Data getData() {
            return data;
        }

        public void setData(Data data) {
            this.data = data;
        }
    }
    
    public class Data {
        
        private String url;
        private boolean is_sillhouette;
        
        public String getUrl() {
            return url;
        }
        public void setUrl(String url) {
            this.url = url;
        }
        public boolean isIs_sillhouette() {
            return is_sillhouette;
        }
        public void setIs_sillhouette(boolean is_sillhouette) {
            this.is_sillhouette = is_sillhouette;
        }
    }
    
        
}

Facebook可标记的朋友样本响应

{
    "data": [
        {
            "picture": {
                "data": {
                    "url": "dummy_url.jpg",
                    "is_silhouette": false
                }
            },
            "id": "AaJfT2z9C1_tj00pdLMtmCSpsX70e_Hreb4xrY94jzK_lJOK5H9H16jjtZPnUPeyFWSszXZtY5mtA-FBkYaPJ24AV9X-8SXGc7_OxXjVBoCA",
            "name": "John Smith"
        },
        {
            "picture": {
                "data": {
                    "url": "dummy_url.jpg",
                    "is_silhouette": false
                }
            },
            "id": "AaK6xdBkzhkSOtr4C1NOI6TiqU4AUr6wzAFVh6KOivnmYqmOHCY_ThHqiC8Pw-2mOElasdLCCDgMvsmSN-dUaGmXpeEKl6Rtq_HMiZw9hAVMmdpOw",
            "name": "Tom Jerry"
        },
        {
            "picture": {
                "data": {
                    "url": "dummy_url.jpg",
                    "is_silhouette": false
                }
            },
            "id": "AaLlnBhsYq4uXpCob_xz8iEToLXf8au_10cBhNVqpJSoJAriDUOefS_w_cc9pg2wPkyasdo5sha75EwhmwJ1HjlVhtkC8e8mSi57F8v1Eo2U_GM6w",
            "name": "Tabour Michael"
        },
        {
            "picture": {
                "data": {
                    "url": "dummy_url.jpg",
                    "is_silhouette": false
                }
            },
            "id": "AaL3P25QKM7pcdRGasRhq3YwK4ijlKutMOErBdUiAqW9Nw2hXqMfk42gBb-T15szRIG38aUyZgaJwgfQ4mI_3vDCQbm0GkSPA7ZmEfVi3My72k4w",
            "name": "Robert Paul"
        }
    ],
    "paging": {
        "cursors": {
            "after": "QWFMS2ZzRnV1eFNyZzloRW1JNElCcFVUckFJY0hTVll6QXk1QUlObHYtbkJVRW9fdmZ4NTdrV1ZLa3RYUEIzLWw4M1RSTVFsZ0xnOGtLVGRycTVab3lnZnlhaEVQS05RcXpxdXFBWHk3U3VpY3c=",
            "before": "QWFLckx0Z29jNExEUnFSTHF1NXVpNWZrTVVEb1dnajNNTHBRdmlHbjB6MUZpYXZWaXo0cUtqenRFOVFtaTdJSVZBaV84NkpfMGZDZlQ3X0RPT0dwSmhyRFU4M1JtMUgtZU9PMHpSdzFSSXVoQnc="
        }
    }
}
8zzbczxx

8zzbczxx1#

我得到了答案,上面使用的API总是返回朋友的信息给开发者,尝试使用facebook的开发者凭据登录,你会得到油炸名单。Sumbit应用程序的Facebook审查和后得到审查的Facebook。每个应用程序用户都可以招募他/她的朋友。

相关问题