Facebook api multiple request -


i creating facebook application generator. , need check if user has added application on facebook page or not.

in order that, first request facebook api give list of pages. loop through pages. , request apps on each of these pages.

lastly compare appid 1 user created , displays display warning accordingly.

the problem , when loop through each of pageid , request fbapi subpages, request response delayed , each loop completes cycle before results fetched facebook.

here code, quite complex... ideas fix issue highly appreciated.

fb.login(function (response) {      fb.api('/me/accounts', function (apiresponse) {          var totalpages = apiresponse.data.length;         var pageindex = 0;         $.each(apiresponse.data, function (pagenumber, pagedata) {              var pageaccesstoken = pagedata.access_token;             var tabpagename = pagedata.name;             var tabpageid = pagedata.id;              fb.api("/" + tabpageid + "/tabs", function (response) {                  var foundapp = false                  $.each(response.data, function (index, value) {                     var exsistingappid = (value.id).split("app_").pop();                     if (exsistingappid == fbappid) {                         foundapp = true;                     }                 });                  if (foundapp === true) {                      var data = {                         pageid: tabpageid,                         url: window.location.href.split("/").pop()                     }                      $.ajax({                         type: "post",                         url: '/facebook/match',                         contenttype: "application/json",                         data: json.stringify(data),                         success: function (data) {                             if (data == "true") {                                 $("#addtofacebookmodal ul").append("<li><span class='pagetab'><a class='pagetabname' target='_blank' href='https://facebook.com/profile.php?id=" +tabpageid + "'>" +tabpagename + "</a></span><a class='deleteappfrompagetab' data-id='" +tabpageid + "' data-accesstoken='" +pageaccesstoken + "'>[x]</a></li>");                                 alreadyadded.push(true);                             } else {                                 alreadyadded.push(false);                             }                              pageindex++;                              if (pageindex == totalpages) {                                 console.log("total pages = " + totalpages + ", looped through = " + alreadyadded.length);                                 if (alreadyadded.indexof(true) >= 0) {                                     $("#addtofacebookmodal").modal();                                 } else {                                     addtofacebook();                                 }                             }                         }                     });                 }                 else {                     pageindex++;                 }              });          });     }); }, { scope: 'manage_pages' }); 

here pseudocode of doing

var myvariable -fb.api callback function returns response array -loop through response array -get new response array based on previous response in array -loop through each item of new response array , compare myvariable.

the problem responses delayed while loop finishes before responses arrive. result cant compare nested item myvariable.

if "facebook page" mean business page / organization page (not profile), can same information more checking endpoint '/{{page_id}}/tabs/{{app_id}}.

replace page_id id of page want check , app_id app id. don't have working code @ moment, this:

fb.api(     '/' + checkpageid + '/tabs/{{app_id}}',     function (response) {         // console.log(response) figure out how see if installed or not     } ) 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -