2017-04-13 41 views

回答

0

如果你想單獨和每個獲得的每個反應後,你可以使用原始API調用,並把它作爲一個JSONObject。

private int like; 
private int wow; 
private int sad; 
private int love; 
private int haha; 
private int angry; 
private String postId; 

Facebook facebook = new FacebookFactory().getInstance(); 
facebook.getOAuthAppAccessToken(); 

ResponseList<Post> posts = facebook.getFeed(pageName, reading); 
     String pageId = facebook.getPage(pageName).getId(); 
     Paging<Post> paging = posts.getPaging(); 
     while(facebook.fetchNext(paging) != null) { 
      paging = posts.getPaging(); 
      for(int i = 0; i < posts.size(); i++){ 
       this.postId = posts.get(i).getId(); 
       RawAPIResponse res = facebook.callGetAPI(postId+"?fields=reactions.type(LIKE).limit(0).summary(1).as(like),reactions.type(WOW).limit(0).summary(1).as(wow),reactions.type(SAD).limit(0).summary(1).as(sad),reactions.type(LOVE).limit(0).summary(1).as(love),reactions.type(HAHA).limit(0).summary(1).as(haha),reactions.type(ANGRY).limit(0).summary(1).as(angry)"); 
       JSONObject jsonObject = res.asJSONObject(); 
       JSONObject reaction = (JSONObject) jsonObject.get("like"); 
       JSONObject summary = (JSONObject) reaction.get("summary"); 
        this.like = summary.getInt("total_count"); 
         reaction = (JSONObject) jsonObject.get("wow"); 
         summary = (JSONObject) reaction.get("summary"); 
        this.wow = summary.getInt("total_count"); 
         reaction = (JSONObject) jsonObject.get("sad"); 
         summary = (JSONObject) reaction.get("summary"); 
        this.sad = summary.getInt("total_count"); 
         reaction = (JSONObject) jsonObject.get("love"); 
         summary = (JSONObject) reaction.get("summary"); 
        this.love = summary.getInt("total_count"); 
         reaction = (JSONObject) jsonObject.get("haha"); 
         summary = (JSONObject) reaction.get("summary"); 
        this.haha = summary.getInt("total_count"); 
         reaction = (JSONObject) jsonObject.get("angry"); 
         summary = (JSONObject) reaction.get("summary"); 
        this.angry = summary.getInt("total_count"); 

       } 
      if(paging != null) { 
        posts = facebook.fetchNext(paging); 
      } 
+0

感謝這個!我會試試這個。 –