I would like to get the post insights for every post in my feed. I can't to pass the parameters from the function. This is the code:
function load_post(page_id, tok)
{
var data = {
access_token : tok,
};
FB.api("/" + page_id + "/feed?fields=id,name",'get',data ,function (response) {
if (response && !response.error) {
console.log(response);
for (var i = 0; i < response.data.length; i++) {
var r = "";
(function(post_id, data, r) {
FB.api("/" + post_id + "/insights/post_impressions",'get',data ,function (response_insight) {
r = response_insight.data[0].values[0].value;
});
})(response.data[i].id, data, r);
alert(r);
}
}
});
}
I don't know where is the error. I'm new in jquery/javascript and I think is a function problem. Can you help me? Thanks a lot.
PS: my goal is to take response_insight.data[0].values[0].value value
this is the response_insight response:
data: Array[1]
0: Object
description: "Lifetime: The number of impressions of your Page post. (Total Count)"
id: "my_id_post/insights/post_impressions/lifetime"
name: "post_impressions"
period: "lifetime"
title: "Lifetime Post Total Impressions"
values: Array[1]
0: Object
value: 676