相关疑难解决方法(0)

如何使用promises和递归通过Facebook Graph API检索用户的所有帖子?

我目前正在开发一个使用Facebook Graph API的网络应用程序.

我想要实现的是获取用户的所有帖子.

但是,这并不容易,因为我必须对结果进行分页.

目前,我正在兑现承诺.

我试图实现的是用post对象填充数组.

因此,我使用的promises和递归不能按预期工作.

我的代码目前看起来如下:

// Here I retrieve the user with his or her posts,
// just the first 25 due to pagination
if (accessToken) {
  return new Promise(resolve => {
    FB.api('/me?fields=id,name,posts&access_token=' + accessToken, response => {
      this.get('currentUser').set('content', response);
      resolve()
    })
  })
}

// Returns all posts of a given user
function getAllPostsOfUser(posts, postsArr) {
  // Process each post of the current pagination level
  for (var post of posts.data) {
    // Only store meaningful posts …
Run Code Online (Sandbox Code Playgroud)

javascript recursion facebook-graph-api facebook-javascript-sdk es6-promise

2
推荐指数
1
解决办法
1222
查看次数