1

Have looked around and can't quite find the answer. I am trying to run a promise which executes a fulfil statement once all facebook api pages have been iterated through and saved to an array.

I know the function's ugly but I'm having a go to see how far I can get with promises.

function pageThroughLikes(facebookPostArray) {
  var testArray = []
  return new Promise(function (fulfill, reject) {
    facebookPostArray.forEach(function(array) {
      array.forEach(function(innerObject) {
        if ('likes' in innerObject) {
          if ('paging' in innerObject.likes) {
            if ('next' in innerObject.likes.paging) {
              nextPage = innerObject.likes.paging.next;
              currentPostId = innerObject.id;
              currentDataLength = innerObject.likes.data.length;
              i = 0;
              do{
                $.get(nextPage, function(nextLikePageData) {
                  likeData = {};
                  likeData.id = currentPostId;
                  likeData.likes = {};
                  likeData.likes.data = nextLikePageData.data
                  likeData.likes.paging = nextLikePageData.paging
                  console.log(likeData)
                  testArray.push(likeData);
                  facebookPostArray.push(testArray);
                  console.log('pushed to postArray')
                })
                i += 1;
                } while (currentDataLength != 0 && i > 10)
              }
           }
         }
      })
   });
   fulfill();
   console.log('paged through likes')
 })
}

At the moment once this function has completed I would like to run a 'test' function which converts my resulting array into CSV format and downloads a CSV file.

Here's my test function:

function test() {
  var convertedPostCSV = convertArrayOfObjectsToCSV(postArray);
  downloadCSV(convertedPostCSV);
}

And here's my running order for functions:

$(document).ready(function() {
  getPostLikes().then(function() {
    pageThroughLikes(postArray).then(function() {
      test();
    });
  });
});

What I'm struggling with is that my 'test()' function is running before the data from new pages of likes is added to my 'facebookPostArray', or before the pageThroughLikes function ends.

Hoping someone can give me some advice/point me in the right direction.

EDIT

Ok, I have reformatted my code as @Winter Soldier has suggested but I'm still getting an uncaught error for the processData function.

Here's my code:

function pageThroughLikes(facebookPostArray) {
 console.log('paging through likes')
 var testArray = []
 var promiseList = [];
 return new Promise(function (fulfill, reject) {
   facebookPostArray.forEach(function(array) {
       array.forEach(function(innerObject) {
         if ('likes' in innerObject) {
           if ('paging' in innerObject.likes) {
             if ('next' in innerObject.likes.paging) {
               nextPage = innerObject.likes.paging.next;
               currentPostId = innerObject.id;
               currentDataLength = innerObject.likes.data.length;
               i = 0;
                 do{
                   promiseList.push(
                     $.ajax({url : nextPage
                       }))
                       i += 1;
                     } while (currentDataLength != 0 && i > 10)
                }
            }
        }
   });
   return promiseList;
   console.log('paged through likes')
})

 processData = function(nextLikePageData){
    likeData = {};
                  likeData.id = currentPostId;
                  likeData.likes = {};
                  likeData.likes.data = nextLikePageData.data
                  likeData.likes.paging = nextLikePageData.paging
                  console.log(likeData)
                  testArray.push(likeData);
                  facebookPostArray.push(testArray);
                  console.log('pushed to postArray')
  return likeData;
}

$(document).ready(function() {
  getPostLikes().then(function() {
  $.when.apply(pageThroughLikes(postArray), this).done(function() {

    var testArray = []
    $.each(arguments, function(k, v){
        var dt = processData(v[0]);
        testArray.push(dt);
        facebookPostArray.push(dt);
    });
    console.log(testArray)
    test(testArray); // OR
    test(facebookPostArray);
   });
 });
});

function test(postArray) {
  var convertedPostCSV = convertArrayOfObjectsToCSV(postArray);
  downloadCSV(convertedPostCSV);
}

EDIT 2.0

Here's my full code in all its ugliness. Just for reference. Figure the issue could be with something I have hidden away somewhere in the rest of my code so potentially worth showing you in full...

var facebookKey = config.FACEBOOK_KEY;

// ASSIGN QUERY TO VARIABLE

var likePage = getQueryVariable("likePage");
var sinceDate = getQueryVariable("sinceDate");
var likeArray = [];
var postArray = [];


function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split('&');
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split('=');
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  alert("Query Variable " + variable + " not found");
}

console.log("Page Search: " + likePage);
console.log("Since: " + sinceDate)

// FIND DATA FOR FACEBOOK PAGE POSTS SINCE CHOSEN DATE 

$(document).ready(function() {
  getPostLikes().then(function() {
  $.when.apply(pageThroughLikes(postArray), this).done(function() {
    var testArray = []
    $.each(arguments, function(k, v){
        var dt = processData(v[0]);
        testArray.push(dt);
        facebookPostArray.push(dt);
    });
    console.log(testArray)
    test(testArray); // OR
    test(facebookPostArray);
   });
 });
});

function test(postArray) {
  var convertedPostCSV = convertArrayOfObjectsToCSV(postArray);
  downloadCSV(convertedPostCSV);
}

function getPostLikes(response) {
  return new Promise(function (fulfill, reject) {
    $.get("https://graph.facebook.com/v2.8/"+ likePage + "?fields=access_token,posts.since(" + sinceDate + "){likes{id}}&access_token=" + facebookKey, function (facebookData) {

      var likePageId = facebookData.id;
      var testPostArray = [];
      if ('posts' in facebookData) {
        var nextPage = facebookData.posts.paging.next;
        var check = 0;

        postArray.push(facebookData.posts.data);

        var currentDataLength = " "
        var i = 0
        if ('paging' in facebookData.posts) {
          console.log("new page available");
          do {
            $.ajax({
              async: false,
              type: "GET",
              url: nextPage,
              success: function(nextPageData) {
                console.log("New Page Accessed: " + nextPage)
                i++;
                console.log("Page Number: " + i)
                testPostArray.push(nextPageData.data);
                if ('paging' in nextPageData) {
                  nextPage = nextPageData.paging.next;
                  console.log("next page assigned");
                }
                currentDataLength = nextPageData.data.length;
                console.log(currentDataLength);
              }
            });
            console.log("DATA LENGTH: " + currentDataLength);
          } while (currentDataLength > 0);
          testPostArray.forEach(function(element) {
            console.log(element)
            postArray.push(element);
            fulfill();
          });
        }
      } else {
        console.log('Error: No facebook posts since this date!')
        reject();
      }
      console.log(postArray)
    });
  })
};
console.log("Downloading...")


function pageThroughLikes(facebookPostArray) {
 console.log('paging through likes')
 var testArray = []
 var promiseList = [];
   facebookPostArray.forEach(function(array) {
       array.forEach(function(innerObject) {
         if ('likes' in innerObject) {
           if ('paging' in innerObject.likes) {
             if ('next' in innerObject.likes.paging) {
               nextPage = innerObject.likes.paging.next;
               currentPostId = innerObject.id;
               currentDataLength = innerObject.likes.data.length;
               i = 0;
                 do{
                   promiseList.push(
                     $.ajax({url : nextPage
                       }))
                       i += 1;
                     } while (currentDataLength != 0 && i > 10)
              }
             }
           }
         })
   });
   console.log('paged through likes')
   return promiseList;
}

 processData = function(nextLikePageData){
    likeData = {};
                  likeData.id = currentPostId;
                  likeData.likes = {};
                  likeData.likes.data = nextLikePageData.data
                  likeData.likes.paging = nextLikePageData.paging
                  console.log(likeData)
                  testArray.push(likeData);
                  facebookPostArray.push(testArray);
                  console.log('pushed to postArray')
  return likeData;
}


  // AUTO DOWNLOAD CSV FILE

  function downloadCSV(args) {
    var data, filename, link;
    var csv = convertArrayOfObjectsToCSV(postArray);

    if (csv == null) return;

    filename = args.filename || 'export.csv';

    if (!csv.match(/^data:text\/csv/i)) {
      csv = 'data:text/csv;charset=utf-8,' + csv;
    }
    data = encodeURI(csv);

    link = document.createElement('a');
    link.setAttribute('href', data);
    link.setAttribute('download', filename);
    link.click();
  }
  // CONVERT FACEBOOK POSTS OBJECTS TO CSV FORMAT

  function convertArrayOfObjectsToCSV(args) {
    var result, ctr, keys, columnDelimiter, lineDelimiter, data;

    data = args || null;
    if (data == null || !data.length) {
      return null;
    }

    columnDelimiter = args.columnDelimiter || ',';
    lineDelimiter = args.lineDelimiter || '\n';

    keys = Object.keys(data[0]);

    result = '';
    result += "user_id" + columnDelimiter + " post_id" + columnDelimiter + " page_id";
    result += lineDelimiter;

    data.forEach(function(item) {
      item.forEach(function(post) {
        if ('likes' in post) {
          var likeArray = post.likes
          likeArray.data.forEach(function(like) {
            result += like.id + columnDelimiter + post.id.split('_').reverse() + lineDelimiter;
          });
        } else {
          result += columnDelimiter + post.id.split('_').reverse() + lineDelimiter;
        };
      });
    });
    console.log('converted to CSV')
  return result;
  }

EDIT 3.0

Function is almost fixed, only issue is that its not looping. Runs perfectly once though!

function pageThroughLikes(facebookPostArray) {
 console.log('paging through likes')
 var testArray = []
 var promiseList = [];
 // return new Promise(function (fulfill, reject) {
   facebookPostArray.forEach(function(array) {
       array.forEach(function(innerObject) {
         if ('likes' in innerObject) {
           if ('paging' in innerObject.likes) {
             if ('next' in innerObject.likes.paging) {
               nextPage = innerObject.likes.paging.next;
               currentPostId = innerObject.id;
               currentDataLength = innerObject.likes.data.length;
               i = 0;
                 do{
                   promiseList.push(
                     $.ajax({url : nextPage
                       }).then(function(data, b, promise){
                       data.id = currentPostId;
                       if ('paging' in data) {
                         if ('next' in data.paging) {
                           nextPage = data.paging.next;
                         }
                       }
                       console.log(nextPage)
                       return promise;
                       }))
                       i += 1;
                       console.log(i)
                     } while (currentDataLength != 0 && i > 10)
              }
             }
           }
         })
   });
   console.log('paged through likes')
   return promiseList;
}

Edit 4.0

Here's my current code...

Almost everything's finally working, managed to get a bunch of info from loads of late night googling.

var facebookKey = config.FACEBOOK_KEY;

// ASSIGN QUERY TO VARIABLE
var likePage = getQueryVariable("likePage");
var sinceDate = getQueryVariable("sinceDate");
var likeArray = [];
var postArray = [];

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split('&');
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split('=');
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  alert("Query Variable " + variable + " not found");
}
console.log("Page Search: " + likePage);
console.log("Since: " + sinceDate)

// FIND DATA FOR DOJOAPP FACEBOOK PAGE POSTS SINCE CHOSEN DATE

$(document).ready(function() {
  getPostLikes().then(function() {
    // console.log(postArray);
  pageThroughLikes(postArray, test)
 });
});

function test(postArray) {
  var convertedPostCSV = convertArrayOfObjectsToCSV(postArray);
  downloadCSV(convertedPostCSV);
}

function getPostLikes(response) {
  return new Promise(function (fulfill, reject) {
    $.get("https://graph.facebook.com/v2.8/"+ likePage + "?fields=access_token,posts.since(" + sinceDate + "){likes{id}}&access_token=" + facebookKey, function (facebookData) {
      var likePageId = facebookData.id;
      var testPostArray = [];
      if ('posts' in facebookData) {
        var nextPage = facebookData.posts.paging.next;
        var check = 0;
        postArray.push(facebookData.posts.data);
        var currentDataLength = " "
        var i = 0
        if ('paging' in facebookData.posts) {
          console.log("new page available");
          do {
            $.ajax({
              async: false,
              type: "GET",
              url: nextPage,
              success: function(nextPageData) {
                console.log("New Post Page Accessed: " + nextPage)
                i++;
                console.log("Paging Through Posts: " + i)
                testPostArray.push(nextPageData.data);
                if ('paging' in nextPageData) {
                  nextPage = nextPageData.paging.next;
                  console.log("next page assigned: " + nextPage);
                }
                currentDataLength = nextPageData.data.length;
                console.log(currentDataLength);
              }
            });
            console.log("DATA LENGTH: " + currentDataLength);
          } while (currentDataLength > 0);
          testPostArray.forEach(function(element) {
            // console.log(element)
            postArray.push(element);
            fulfill();
          });
        }
      } else {
        console.log('Error: No facebook posts since this date!')
        reject();
      }
      // console.log(postArray)
    });
  })
};
console.log("Downloading...")


function pageThroughLikes(facebookPostArray, callback) {
 console.log('paging through likes')
 var testArray = []
 var promiseList = [];
   facebookPostArray.forEach(function(array) {
     array.forEach(function(innerObject) {
       if ('likes' in innerObject && 'paging' in innerObject.likes && 'next' in innerObject.likes.paging) {
       var nextPage = innerObject.likes.paging.next;
       console.log('new likes page assigned: ' + nextPage);
       var currentPostId = innerObject.id;
       var noMorePages = false;
       var i = 0;
       do{
         $.ajax({
           url: nextPage,
           success: function(nextLikePageData) {
             createLikeObject(nextLikePageData, currentPostId, checkForPagesOfLikes, nextLikePageData, noMorePages)
             if ('paging' in nextLikePageData && 'next' in nextLikePageData.paging) {
               nextPage = nextLikePageData.paging.next;
             }
            }
          })
         i += 1
         console.log(i)
        } while (noMorePages = false);
       }
     })
   });
   console.log('paged through likes')
   callback();
}

function createLikeObject(likeData, postId, callback, args, fail) {
  likeArrayFormat = [];
  likeObject = {};
  likeObject.likes = {};
  likeObject.id = postId;
  likeObject.likes.data = []
  likeData.data.forEach(function(like) {
    likeObject.likes.data.push(like);
  });
  likeArrayFormat.push(likeObject);
  postArray.push(likeArrayFormat);
  console.log('pushed new like data to postArray')
  callback(args, fail)
}

function pushToArray(item, array, callback) {
  array.push(item);
  callback()
}

function checkForPagesOfLikes(data, noMorePages) {
  if ('paging' in data && 'next' in data.paging) {
      return true;
      console.log('NEW PAGE FOUND')
    }
  else {
    noMorePages = true;
    console.log('NO MORE PAGES OF LIKES FOR CURRENT OBJECT')
  }
}

  // AUTO DOWNLOAD CSV FILE
  function downloadCSV(args) {
    var data, filename, link;
    var csv = convertArrayOfObjectsToCSV(postArray);
    if (csv == null) return;
    filename = 'export.csv';
    if (!csv.match(/^data:text\/csv/i)) {
      csv = 'data:text/csv;charset=utf-8,' + csv;
    }
    data = encodeURI(csv);
    link = document.createElement('a');
    link.setAttribute('href', data);
    link.setAttribute('download', filename);
    link.click();
  }

  // CONVERT FACEBOOK POSTS OBJECTS TO CSV FORMAT

  function convertArrayOfObjectsToCSV(args, callback) {
    var result, ctr, keys, columnDelimiter, lineDelimiter, data;
    // console.log(args)
    data = args || null;
    if (data == null || !data.length) {
      return null;
    }
    columnDelimiter = args.columnDelimiter || ',';
    lineDelimiter = args.lineDelimiter || '\n';
    keys = Object.keys(data[0]);
    result = '';
    result += "user_id" + columnDelimiter + " post_id" + columnDelimiter + " page_id";
    result += lineDelimiter;
    // console.log(args)
    args.forEach(function(object) {
      // console.log(object)
      // console.log(object.length)
      if (object.length != 0) {
        object.forEach(function(item) {
          if ('likes' in item && 'data' in item.likes) {
            var postId = item.id;
            item.likes.data.forEach(function(likeId) {
              if ('id' in likeId) {
                // console.log(likeId)
                var likeArray = likeId;
                // console.log(likeArray)
                  result += likeArray.id + columnDelimiter + postId.split('_').reverse() + lineDelimiter;
              } else {
                result += columnDelimiter + postId.split('_').reverse() + lineDelimiter;
              };
            });
          }
        });
      }
    })
    console.log('converted to CSV')
  return result;
  callback();
  }

Big issue is that at the moment, convertArrayObObjectsToCSV is running before the createLikeObject function is complete. Thought callbacks would've worked but it seems I haven't got something quite right.

  • Each of those `$.get()` calls will start another asynchronous operation. Your code calls `fulfill()` before those finish. – Pointy Nov 21 '16 at 14:56
  • Do you need to call fulfull(). Can you try without it? – Winter Soldier Nov 21 '16 at 14:58
  • @WinterSoldier, trying to get to grips with promises where possible, so I'd like to use them to solve this (unless its completely unnecessary of course!). – LastMan0nEarth Nov 21 '16 at 15:03
  • @Pointy, so would it be reasonable to assume I have to add another promise to my `$.get()` loop? – LastMan0nEarth Nov 21 '16 at 15:07
  • Your get call takes its own time to resolve while your promise's fulfill() gets called immediately as pointed out by @Pointy. What you might want to do is collect all the promises of get/ajax calls and call [when](https://api.jquery.com/jquery.when/) may be, so that they are all resolved at the same time. – Winter Soldier Nov 21 '16 at 15:15
  • you should learn about recursive functions in javascript, they are useful for getting all data with paging. – andyrandy Nov 21 '16 at 15:15
  • you can´t call everything at the same time. in order to do paging, you need to wait for every call and use the "next" link in the returned value. – andyrandy Nov 21 '16 at 15:16
  • for example: http://stackoverflow.com/questions/5023757/how-does-paging-in-facebook-javascript-api-work – andyrandy Nov 21 '16 at 15:18
  • not sure why you use jquery for this, better use the official javascript sdk. – andyrandy Nov 21 '16 at 15:18
  • @LastMan0nEarth is your do-while not looping? – Winter Soldier Nov 22 '16 at 14:47
  • @WinterSoldier no, I'm pretty sure its because the nextPage is not being reassigned to outside of my do while. I have tested this by changing the while condition to i < 5. This leads to the page looping once. And then until i = 5 I get the same pagedata each loop – LastMan0nEarth Nov 22 '16 at 15:01
  • @WinterSoldier trouble is that if I reassign nextPage, it doesn't seem to be taking effect for the next loop.... – LastMan0nEarth Nov 22 '16 at 15:03
  • have you examined(console.log or something) the nextPage at this line=> nextPage = data.paging.next; – Winter Soldier Nov 22 '16 at 15:03
  • interesting, its not actually getting set. – LastMan0nEarth Nov 22 '16 at 15:06
  • May be your API call is not returning the data you need at all / there is an issue with `if ('paging' in data) { if ('next' in data.paging) { nextPage = data.paging.next; } }` – Winter Soldier Nov 22 '16 at 15:09
  • Right, at the moment I've changed the while condition to `while (currentDataLength != 0 && i < 2)` . With this condition, I get the first page of data perfectly, then the second page of data runs twice instead of once for the second and once for the third – LastMan0nEarth Nov 22 '16 at 15:13
  • I've also noticed that the `currentDataLength` always fulfils the condition `!= 0` as it is assigned above the `do while` loop. If I try to reassign the variable inside my `do while` the `while` condition still picks up the variable assigned before the loop... – LastMan0nEarth Nov 22 '16 at 15:16
  • A do-while executes the logic and then verifies the [condition](http://www.w3schools.com/jsref/jsref_dowhile.asp) – Winter Soldier Nov 22 '16 at 16:17
  • Yes @WinterSoldier sorry I mean to say that the condition is always verified – LastMan0nEarth Nov 22 '16 at 18:15
  • @LastMan0nEarth Could you tell us how this => facebookPostArray object looks like and how you want to process it via pageThroughLikes, you may ignore the non-required attributes/replace them with dummy values - so it gives us an idea. – Winter Soldier Nov 22 '16 at 18:40
  • @WinterSoldier facebookPostArray objects are as follows: object: id: 23234234534_34345346 data: likes: paging: – LastMan0nEarth Nov 23 '16 at 09:19
  • Okay your `pageThroughLikes() 's callback()` on the last line of that method gets executed synchronously while the ajax calls in between do-while are async. – Winter Soldier Nov 23 '16 at 15:55
  • @LastMan0nEarth - I'm afraid, your edit 4.0 is dangerously off-course. You need to understand how [async](https://www.sitepoint.com/javascript-goes-asynchronous-awesome/) works in js. For Now: Remove the callback call from `pageThroughLikes` last line & make the `$.ajax({async :false...})` false like you did for your `getPostLikes` and try it out. It is not the proper approach by any means but can fix your method call chronology – Winter Soldier Nov 23 '16 at 16:05

2 Answers2

0

Here might be one way to do it since you are using get call, I've modified to not use promise at all because ajax returns the promise anyway.

It is a pseudo code, you might have to tweak it a bit to get it running

function pageThroughLikes(facebookPostArray) {
  var testArray = []
  var promsieList = []
    facebookPostArray.forEach(function(array) {
      array.forEach(function(innerObject) {
        if ('likes' in innerObject) {
          if ('paging' in innerObject.likes) {
            if ('next' in innerObject.likes.paging) {
              nextPage = innerObject.likes.paging.next;
              currentPostId = innerObject.id;
              currentDataLength = innerObject.likes.data.length;
              i = 0;
              do{
                promsieList.push(
                $.ajax({url : nextPage                  
                }))
                i += 1;
                } while (currentDataLength != 0 && i > 10)
              }
           }
         }
      })
   });
   console.log('paged through likes')
   return promiseList();    
}

processData = function(nextLikePageData){
    likeData = {};
                  likeData.id = currentPostId;
                  likeData.likes = {};
                  likeData.likes.data = nextLikePageData.data
                  likeData.likes.paging = nextLikePageData.paging
                  console.log(likeData)
                  testArray.push(likeData);
                  facebookPostArray.push(testArray);
                  console.log('pushed to postArray')
  return likeData;
}

$(document).ready(function() {
  getPostLikes().then(function() {
  $.when.apply(this, pageThroughLikes(postArray)).done(function() {
    //debug to examine the arguments object, you'll notice its an array of arrays
    var testArray = []
    $.each(arguments, function(k, v){
        var dt = processData(v[0]);
        testArray.push(dt);
        facebookPostArray.push(dt);         
    });
    console.log(testArray)
    test(testArray); // OR
    test(facebookPostArray);
   });
 });
});

function test(postArray) {
  var convertedPostCSV = convertArrayOfObjectsToCSV(postArray);
  downloadCSV(convertedPostCSV);
}

EDIT:

  • The arguments is a default object returned by the jquery $.when function.
  • This is a collection of subarrays and each subarray consists of data, status & promise object.
  • I'm assuming that you need to consolidate the data from all the get calls into a testArray so, that is what is being done in the when call
Winter Soldier
  • 2,607
  • 3
  • 14
  • 18
  • In the `$(document).ready` function which arguments should I be using to resolve the data? This is the part I think I'm failing to understand with resolves. Are you trying to send all of the data collected in `pageThroughLikes` to the `processedData` array before running test? And if so, why does this need to be done? – LastMan0nEarth Nov 21 '16 at 15:43
  • Interesting. Is processData something inbuilt to $.when? Getting a reference error as it's not defined. – LastMan0nEarth Nov 21 '16 at 15:58
  • Answered your questions in the post. Also I fail to understand why you are iterating through the same array of facebookPostArray to draw the parameters to get call and using the same array to push the results? – Winter Soldier Nov 21 '16 at 15:59
  • No processData is something I made up which has the same processing logic that you had from your huge pageThroughLikes's $.get function so that I can process each result accordingly – Winter Soldier Nov 21 '16 at 16:00
  • Ok, just re-read and understand much better now. Like you, I've extracted my pageThroughLikes $get function to the processData function. However I do still have a `processData is undefined` error, despite making this change. – LastMan0nEarth Nov 21 '16 at 16:19
  • Could you please post the changed code back in the question. Leave the existing one for reference and add the new code below it with a title EDIT. That will help me cross check. Thanks – Winter Soldier Nov 21 '16 at 16:29
  • @ LastMan0nEarth You don't need the promise anymore in pageThroughLikes nor do you need to return a Promise. Please have a look at my answer. Just return the promsieList – Winter Soldier Nov 21 '16 at 16:41
  • Have taken the promise out. Failed to realise it was there. In your example are promsieList and promiseList supposed to be two different things? – LastMan0nEarth Nov 21 '16 at 16:49
  • nah, that must have been a spell error. Sorry about that. :). It must be promsieList everywhere. Do you still get the undefined error? – Winter Soldier Nov 21 '16 at 16:51
  • No problem! Still getting that error though unfortunately :( – LastMan0nEarth Nov 21 '16 at 16:53
  • Alright. Could you make a sample [fiddle](https://jsfiddle.net). Lets try to collaborate on a fiddle if possible. Meanwhile I'll post you a working example – Winter Soldier Nov 21 '16 at 16:58
  • Here is a sample working link to use [when](https://jsfiddle.net/randomfifaguy/8jz58y6s/4/). Also I corrected the answer, I mis-swapped the when params. – Winter Soldier Nov 21 '16 at 17:27
-2

You need to fullfil/resolve the value that you need from promise. Call the function fulfill with a value you that you need.For example if you want to resolve an array:

fullfill(array);
Bhagya M
  • 255
  • 5
  • 7
  • Would you be able to elaborate on this? If I add the facebookPostArray argument to my fulfill function I get the same result. Or do you mean I need to assign a variable when my $.get() function ends and pass this into my fulfill? – LastMan0nEarth Nov 21 '16 at 15:19