1
I have this following code where return comments from a post on facebook.
function pegaFoto(id){
var url2 = 'https://graph.facebook.com/v2.8/' + from[id] + '/picture?fields=url';
$.getJSON(url2, function(res2){
for (var key2 in res2.data) {
foto[id] = res2.data[key2].url;
console.log(res2.data[key2].url);
}
});
}
function refreshCounts() {
var url = 'https://graph.facebook.com/v2.8/********_*********/comments?fields=from{id}, message&access_token=' + access_token;
$.getJSON(url, function(res){
for (var key in res.data) {
comentario[key] = res.data[key].message;
from[key] = res.data[key].from.id;
pegaFoto(key);
console.log(comentario[key]);
console.log(foto[key]);
}
});
}
What’s weird is that the second function works perfectly and the top function doesn’t work. url2 variable is being set correctly but $.getJSON does not perform and I have no idea why
If you catch the
url
and play in the browser, returns the data?– Marco Giovanni
return yes friend
– Marciel Fonseca
from[id]
wouldn’t just beid
? Where is thefrom
?– BrTkCa
no, that’s correct. id is actually the index of the array that contains the ids of people who commented. Only thing not working is the get.JSON that doesn’t run, because url2 is set normally when I check
– Marciel Fonseca
Dude, I did a test using the facebook of the mark: https://graph.facebook.com/v2.8/4/picture?fields=url. The return is not a JSON, it is an image. You’ll have to use
$.ajax
and treat that image. Or pass some argument in the url that converts the return to JSON.– BrTkCa
hadn’t realized it. Because in Graph api explorer returns json, that tense lost hours because of this "confusion"
– Marciel Fonseca
Yeah, I’m reading the documentation to see if I can find anything..
– BrTkCa
What’s the tip then? I’m not very experienced with ajax, I program by hobby and I’m used to the face API but for this I did not expect, I need to return the image url
– Marciel Fonseca
I got it bro, thanks to this balcony of appearing the photo and not the data, I simply had to include at the end of the url the parameter
redirect=false
and gave right thanks– Marciel Fonseca
Good :) another way is to invoke their api in javascript. But if it’s worked out better yet.
– BrTkCa
@Marcielfonseca Answer your question with this solution, so when someone looks maybe your solution is useful.
– BrTkCa
@Lucascosta I accepted your reply, thank you
– Marciel Fonseca