首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从RestFB中的Post获取用户ID注释

从RestFB中的Post获取用户ID注释
EN

Stack Overflow用户
提问于 2018-05-03 23:29:28
回答 2查看 231关注 0票数 1

我需要用户(或者至少是ID )在帖子中发表评论。

这是一个java桌面应用程序。我获得了存取令牌并选择了所有权限,只进行测试。

我尝试过这种方法,但没有成功:

代码语言:javascript
复制
com.restfb.types.Page fetchedPage = facebookClient.fetchObject(pageName, com.restfb.types.Page.class);
//String pageID = fetchedPage.getId();
//String postID = "some post id from the 'fetchedPage'"
String postParam = "type,from,created_time,message,likes.summary(true),comments.order(chronological).summary(true){from{id}}";
com.restfb.types.Post fetchedPost = facebookClient.fetchObject(pageID + "_" + postID, com.restfb.types.Post.class, com.restfb.Parameter.with("fields", postParam));//the part 'from' of the 'comments' don't work as expected, returns null, that > "comments.order(chronological).summary(true){from{id}}"

com.restfb.types.Comments postComments = fetchedPost.getComments();
if(postComments != null){
    for(com.restfb.types.Comment comment : postComments.getData()){
        if(comment != null){
            //curiously I can not access the user who made the comment, but if it is a page that made a comment in the post it perfectly returns the user (which is a page)
            System.out.println("comment: " + comment.getFrom());// >> 'getFrom()' is null << that is what I need, the or at least the ID as told before.
            com.restfb.types.Comment fetchedComment = facebookClient.fetchObject(pageID + "_" + comment.getId(), com.restfb.types.Comment.class, com.restfb.Parameter.with("fields", "from,id,message,created_time,like_count,comment_count"));
            System.out.println("fetchedComment:  " + fetchedComment);//fetching like that the 'getFrom()' is null too...
            System.out.println();
        }
    }
}

有什么暗示吗?抱歉,糟糕的英语

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-05-04 19:08:56

如果您只需要注释id、创建注释的用户以及她的名称,则可以使用以下代码。

代码语言:javascript
复制
String postId = pageID + "_" + postID; // you should not generate it, take it from the feed
Connection<Comment> commentConnection = facebookClient.fetchConnection(postId + "/comments", Comment.class,
  Parameter.with("fields", "id,from{name,id}"));

for (List<Comment> commentList : commentConnection) {
  for (Comment comment : commentList) {
    System.out.println("Comment ID: " + comment.getId());
    System.out.println("User ID: " + comment.getFrom().getId());
    System.out.println("User Name: " + comment.getFrom().getName());
  }
}
票数 0
EN

Stack Overflow用户

发布于 2018-05-04 02:54:59

您可以通过以下方式获得访问令牌:

  1. 登录你的脸书
  2. 转到你的个人资料页面
  3. 右击“查看页面源”
  4. 用键查找文本:"access_token“
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50165097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档