我想知道有多少人在 java 中使用 restfb 在我的 Facebook 页面上看到了我的 post

I want to read how many people have seen my post in my facebook page using restfb in java

使用下面的类似内容,我能够阅读我的 Facebook 页面中的 post 收到了多少反应(详细)。 https://restfb.com/cookbook/ 现在我需要阅读有多少人看过 posts 特别是我需要限制日期。例如:昨天有多少人看到我的 post 和 id x?我不需要人员列表,只要有多少人看过,还有多少人点击打开,以防有图片。 基于 https://developers.facebook.com/docs/graph-api/reference/post/seen/ 我写了下面的代码: 我的代码:

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

错误是:

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)

提前一百万致谢

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