【问题标题】:facebook batch request with jsonpath带有jsonpath的facebook批处理请求
【发布时间】:2013-03-25 09:47:48
【问题描述】:

使用 Facebook,我需要知道谁(哪个用户)对 facebook 页面上的帖子发表了评论。 我在我的 javascript 文件中使用 facebook-batch-requests 发出两个请求,第一个请求所有帖子,第二个请求每个帖子的请求。很高兴,如果我可以只选择有一些 cmets 的帖子。

FB.api('/', 'POST', {
  batch: [
  {
    // all posts from page from last year
    'method': 'GET',
    'name': 'posts_page_year',
    'omit_response_on_success': false,
    'relative_url': fbPageID + '/posts?since=2012-01-01&until=' + timeNow + '&limit=200000'
  },
  {
    // all post-ids from last year
    'method': 'GET',
    "relative_url": "/{result=posts_page_year:$.data.*.id[?(@.comments.count!=0)]}"
  }
]
}, function(response) {
  callback(response);
}
);

我的问题是第二个批处理请求,它返回一个错误(#803)。我试了一下。

{
    // all post-ids from last year
    'method': 'GET',
    "relative_url": "/{result=posts_page_year:$.data.0.id}"
}

返回一个带有第一个后请求的对象。一切都是好的。但我希望每个帖子都有这个,而不仅仅是第一个。

{
    // all post-ids from last year
    'method': 'GET',
    "relative_url": "/{result=posts_page_year:$.data.*.id}"
}

返回错误 (#803) 您请求的某些别名不存在以及所有 ID 的列表。

{
    // all post-ids from last year
    'method': 'GET',
    "relative_url": "/{result=posts_page_year:$.data.*.id[?(@.comments.count!=0)]}"
}

返回此错误: (#803) 您请求的某些别名不存在:{result=posts_page_year:$.data.*.id[

我几乎尝试了所有方法并需要您的帮助,因为我不知道如何解决问题。 THX!

【问题讨论】:

  • 我已经解决了这个问题。但此刻,我不记得了——那是很久以前的事了。如果有人对此解决方案感兴趣,请添加评论。
  • 您好,我对解决方案很感兴趣 :)
  • 嗨@Morti,您可以在我的answer below 中阅读解决方案。

标签: facebook-graph-api facebook-javascript-sdk jsonpath facebook-batch-request


【解决方案1】:

在 Facebook batch documentation 中,它声明:

请注意,出于安全原因,过滤器和脚本 JSONPath 构造 JSONPath 表达式中不允许使用。

这可能意味着你不能使用像?(@.comments.count!=0)这样的代码

【讨论】:

    【解决方案2】:
    FB.api('/', 'POST', {
      batch: [
        {
          // 0: all likes from user
          'method': 'GET',
          'relative_url': 'me/likes'
        },
        {
          // 1: all user-posts from last month
          'method': 'GET',
          'relative_url': 'me/posts?since=' + timeMonthAgo + '&until=' + timeNow + '&limit=200000'
        },
        {
          // 2: all user-posts from last year
          'method': 'GET',
          'relative_url': 'me/posts?since=' + timeYearAgo + '&until=' + timeNow + '&limit=200000'
        }
      ]
      }, function (response) {
        callback(response);
      }
    );
    

    我必须设置一个限制,以便每个响应现在都有内容限制。可以将限制设置为不可能的大数。您还必须使用sinceuntil 参数设置时间范围。

    我希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-08
      • 2017-10-25
      • 1970-01-01
      • 2018-08-10
      相关资源
      最近更新 更多