Issues pulling content from Facebook Comment Box, in Rails using JS SDK
So I am working on a Rails project and I am using the facebook JS SDK and
have the comment box in my page. I followed this link to fix a javascript
issue where it could not find the FB variable. But now I am getting an
issue that feed.text is undefined...
Basically what I am trying to do is when a user comments, I want to
trigger an email to the owner of that page. The email will have the
posting users name, time, and comment. But for some reason I am not
getting any of the information when the comment is posted. I am getting
the trigger that lets me know a new message has been posted tho.
Then I started poking around on the FB developer site a little more where
there was a blog posts about trying to do what I am having difficulties
with here. But the problem with that is, it is for php and I am using
RoR... But I decided to keep looking into what could be the issue.
I looked at the page that is supposed to have all the content from the
comments, but when I went there all I saw was:
{
"http://www.gofitcause.com/missions/51b61acedba888849d00001b": {
"comments": {
"data": [
]
}
}
}
So now I am a little confused, the issue with the first solution I linked
to seems to be breaking because there is no information being logged
above. So I guess my question is pretty broad but I basically just need
insight on why I can't seem to find the content for the comments that are
being posted.
Below is the code I am using that was taken from the first link:
<script>
window.fbAsyncInit = function () {
//FB.init({ appId: 'your-app-id', cookie: true, xfbml: true, oauth:
true });
if (typeof facebookInit == 'function') {
facebookInit();
}
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src =
"//connect.facebook.net/en_US/all.js#xfbml=1&appId=452464168153305";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function facebookInit(){
FB.Event.subscribe('comment.create', function(response) {
FB.api({
method: 'fql.query',
query: "select post_fbid, fromid, object_id, text, time from
comment where object_id in (select comments_fbid from link_stat
where url ='<%= mission_url(@mission)%>') or object_id in
(select post_fbid from comment where object_id in (select
comments_fbid from link_stat where url ='<%=
mission_url(@mission)%>')) order by time desc limit 1"
},
function(response) {
var feed = response[0];
alert(feed.text);
}
);
});
}
</script>
And this is the error I see in firebug:
TypeError: feed is undefined
alert(feed.text);
Thanks for reading, any help or insight would be appreciated.
No comments:
Post a Comment