I am trying to get some output parsing results from Facebook graph API (comments on a website)
Here is the script:
if (document.getElementById('comments')) {
var url = "https://graph.facebook.com/fql?q=select+xid%2C+username%2C+text%2C+time+from+comment+where+object_id+in+%28select+comments_fbid+from+link_stat+where+url+%3D%27http%3A%2F%2Fdroidsnip.blogspot.com%27%29";
$.getJSON(url, function(data){
var name = data.data;
document.getElementById('comments').innerHTML = name[0].text;
});
}
and an html:
<p id="comments">Hello World</p>
And i canon get results from the script to be injected in html
Do I have mistakes in script? (I am not very good at js and jQuery)
I can't really debug this script to see until which line it executes (in case if I have it badly written)
Also here: if I use dot notation in data.data
then browser is not complaining, but if i use data["data"]
, then i get mistake in this line, saying i must use dot notation
For me it works:
Make sure you wrapped the code in document.ready statement:
$(document).ready(function(){
if (document.getElementById('comments')) {
var url = "https://graph.facebook.com/fql?q=select+xid%2C+username%2C+text%2C+time+from+comment+where+object_id+in+%28select+comments_fbid+from+link_stat+where+url+%3D%27http%3A%2F%2Fdroidsnip.blogspot.com%27%29";
$.getJSON(url, function(data){
var name = data.data;
document.getElementById('comments').innerHTML = name[0].text;
});
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.