chopu
chopu

Reputation: 27

How to get all post id's of a specific page in facebook

I am extracting the post details of a facebook page. I extracted the json of a particular page and now I have to get id of all the posts of that page. How can I do it using facebook4j.

private static String readpage(Reader rd) throws IOException 
{
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = rd.read()) != -1) 
{
  sb.append((char) cp);
}
return sb.toString();
}

public static JSONObject readurl(String url) throws IOException, JSONException
{
InputStream is = new URL(url).openStream();
try 
{
  BufferedReader rd = new BufferedReader(new InputStreamReader
(is, Charset.forName("UTF-8")));
  String jsonText = readpage(rd);
  JSONObject json = new JSONObject(jsonText);
  return json;
} 
finally
{
  is.close();
}
}
public static void main(String[] args) throws
IOException, JSONException, FacebookException
{ 
JSONObject json = readurl("https://graph.facebook.com/"+s);
}

Upvotes: 0

Views: 713

Answers (1)

Shashwath
Shashwath

Reputation: 452

You can obtain all the post related information of a particular page by referring the following code :

ResponseList<Post> results = facebook.getPosts(searchPost);

                    String userId = "";
                    for (Post post : results) {

                        obj.put("Post Id", post.getId());
                        obj.put("Post message", post.getMessage());
                        obj.put("No of likes on Post", post.getLikes().size());
                        obj.put("Post owner name:", post.getFrom().getName());
                        objArray = new JSONArray();

where obj is a JSON object.

PS:I am using eclipse kepler and facebook4j-core-2.0.2

Upvotes: 1

Related Questions