Using the code below I was able to read how many reactions (in detailed) my posts in my Facebook page have received. https://restfb.com/cookbook/ Now I need to read how many people have seen the posts specially I need to limit the date. For example: how many people have seen my post with the id x, yesterday? I do not need list of people, just how many people have seen and also how many people have clicked to open in case there was a picture. Based on https://developers.facebook.com/docs/graph-api/reference/post/seen/ I wrote the code below: My code :
int postNumber=0
Connection<Post> results = fbclient.fetchConnection(pageID + "/feed", Post.class);
for(List<Post> mypage: results) {
for(Post posted: mypage) {
postNumber++;
String postID=posted.getId();
Post hasSeen=fbclient.fetchObject(postID+"/seen",Post.class, Parameter.with("fields",
"seen_time, total_count"));
System.out.println("post number "+ postNumber+ "has been seen by "+ hasSeen);
}}
The error is :
Received Facebook error response of type OAuthException: (#100) Tried accessing nonexisting field (seen) on node type (PagePost) (code 100, subcode null) 'null - null'
at com.restfb.exception.generator.DefaultFacebookExceptionGenerator$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookExceptionGenerator.java:174)
at com.restfb.exception.generator.DefaultFacebookExceptionGenerator.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookExceptionGenerator.java:61)
at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:794)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:721)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:683)
at com.restfb.DefaultFacebookClient.fetchObject(DefaultFacebookClient.java:276)
Thanks a million in advance
String accessTokenFB= "write your access token";
//System.out.println("accessTokenFB is "+ accessTokenFB);
FacebookClient fbclient=new DefaultFacebookClient(accessTokenFB, Version.VERSION_7_0);
String postID="write your facebook post id";
JsonObject jObj=fbclient.fetchObject(postID + "/insights", JsonObject.class,Parameter.with("metric", "post_clicks, post_impressions"));
//System.out.println(jObj);
JsonValue data=jObj.get("data");
// System.out.println(data);
JsonValue post_clicks=((JsonObject) ( (JsonArray) data).get(0)).get("name");
System.out.println(post_clicks.asString());
JsonValue valueClick= ((JsonObject) ((JsonArray) ((JsonObject) ((JsonArray) data).get(0)).get("values")).get(0)).get("value");
System.out.println(valueClick.asInt());
JsonValue post_impressions=((JsonObject) ( (JsonArray) data).get(1)).get("name");
System.out.println(post_impressions.asString());
JsonValue valueImpressions= ((JsonObject) ((JsonArray) ((JsonObject) ((JsonArray) data).get(1)).get("values")).get(0)).get("value");
System.out.println(valueImpressions.asInt());