3

请注意,这不是一个问题,只是一个代码片段,您可以随意改进它

使用 gson 解析 Facebook GraphObject

我正在研究 Facebook 可标记的朋友,我已经解析了 GraphObject 可能对其他人有帮助。

解析可标记好友功能 :: user_friends 需要权限

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="
        }
    }
}
4

1 回答 1

0

我得到了答案,上面使用api总是将朋友的信息返回给开发者,尝试使用facebook的开发者凭据登录,你会得到炒名单。Sumbit 应用程序用于 facebook 评论,并在获得 facebook 评论后。每个应用程序用户都可以招募他/她的朋友。

于 2014-09-16T07:54:34.017 回答