A simple question about facebook comments plugin - facebook

I'm struggling with a very simple problem. The facebook documentation, as always, didn't give me enough explanation.
I attached a facebook comments plugin to my site. And using a callback of "comment.create" event, I can get information of a just-create comment.
FB.Event.subscribe('comment.create', function(response) {
alert(JSON.stringify(response));
});
The json reponse looks like:
{"href":"http://siteaddress.com/page.htm", "commentID":"111122223333" }
What I like to do now is to retrieve the data of the single comment with the commentID. Although I expected that the following way should work:
https://graph.facebook.com/111122223333
it just gave me "False". I can retrieve all comments attached to that page using:
https://graph.facebook.com/comments?ids=http://siteaddress.com/page.htm
But, what is the right way to retrieve the single comment data just created using the commentID?

I was also facing the same problem... so what i did was , I queried the last posted comment or reply from the fb comments table using fql. Here I sort the comments by time in descending order and pick the top one. though one may think that if two comments are posted at same time, it may cause ambiguity, But in my case i tried and tested it invoving more than 2 users but i always got the expected result.
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 ='URL_OF_THE_COMMENT_BOX') or object_id in (select post_fbid from comment where object_id in (select comments_fbid from link_stat where url ='URL_OF_THE_COMMENT_BOX')) order by time desc limit 1"
},
function(response) {
var feed = response[0];
alert(feed.text)
}
);
});

Hi if you are having comment id then why you dont use FQL and query to Comment Table to get all comment related data?

I am having this same problem. What seems to be happening is that the commentID and parentCommentID are actually just returning the unique ID of that page, and not a unique ID for the comment itself.
The unique ID for an individual comment is the unique ID of the page (that is, the value currently being returned as "commentID") with an underscore followed by another number (8 digits long in the tests I've done). You can look this up directly from the graph the response provided it.
I have logged a bug with Facebook to hopefully get this fixed! Bug at address below:
http://bugs.developers.facebook.net/show_bug.cgi?id=16535

Hm. I can retreive comment data by id (id format like this: 1234567890123456_12345678). Ids i retreive from url like this:
https://graph.facebook.com/comments?ids={$url}

I combined a couple approaches (including from Charsee).
// this query takes a "commentID" and "href". The commentID is returned on comment.create "response" object
// this code requires an escape function "addslashes(str)" to handle single quotes.
var query = "SELECT text, fromid FROM comment WHERE post_fbid='"+addslashes(commentID)+"' AND ( object_id in (select comments_fbid from link_stat where url ='"+addslashes(href)+"') or object_id in (select post_fbid from comment where object_id in (select comments_fbid from link_stat where url ='"+addslashes(href)+"')))";

Related

Why FQL query for Post content returns empty data[]?

I'm trying to run this FQL and get the list of comments on a specific post:
select post_fbid, fromid, object_id, text, time FROM comment WHERE object_id = '518460828241435_546620402092144'
Why it is returning this:
{
"data": [
]
}
PS: I'm testing it on graph api explorer tool.
Thanks for the help! Really appreciate the help!
Use post_id instead of object_id. That is how I am using it.
Or else you are using an incorrect id that you pass as object_id :)

Any way to use elements of FQL attachment media array in multiquery?

I need to get the list of comments for each item in a user's news feed including comments for any media in the feed items.
I'm trying to avoid multiple FQL query roundtrips, so I'd like to use multiquery.
I can get the comments for each post_id in the feed:
{
posts: 'SELECT post_id, attachment FROM stream WHERE filter_key = "nf"',
post_comments: 'SELECT post_id, fromid, text FROM comment WHERE post_id IN (SELECT post_id FROM #posts)'
}
However, there doesn't seem to be a way to reference content in the media elements so I can request the comments for media fbids, e.g.:
photo_comments: 'SELECT object_id, fromid, text FROM comment WHERE object_id in (SELECT attachment.media.fbid FROM #posts)'
This question (How to query FQL Stream by Attachment.Media.Type?) is very similar, but the answer was a bit uncertain & wasn't accepted.
Any suggestions or definitive answer?
Figures -- once I posted the question, I came across an answer to another question (http://facebook.stackoverflow.com/questions/8003581/get-photos-from-stream) that gave me what I needed:
photo_comments: 'SELECT object_id, fromid, text from comment where object_id in (SELECT attachment.media.photo.fbid from #posts)'
The example in my answer was a generic description, but turned out to be close to the actual technique (with the photo object missing in the path).
Hope this helps somebody else doing a similarly narrow search.

Need current syntax for writing an FQL query in PHP

Because using the Graph to get comment information craps out at a certain volume (even with pagination) I need an FQL solution. Unfortunately, all the documentation and blogs I've found contain deprecated samples making it impossible for me to figure out the correct syntax.
I need to understand how to get this:
SELECT object_id, post_id, fromid, time, text, username
FROM comment
WHERE object_id
IN (SELECT comments_fbid FROM link_stat WHERE url='*** EVENT HREF ***')
into a PHP variable so I can access the data from a decoded JSON object like so:
$fql_obj = json_decode($fql_query, true);
I figured this out. For anyone else confused by it you append it to a graph lookup and replace spaces with +s:
$fql_query = "https://graph.facebook.com/fql?q=SELECT+object_id,+post_id,+fromid,+time,+text,+username+FROM+comment+WHERE+object_id+IN+SELECT+comments_fbid+FROM+link_stat+WHERE+url='***EVENTHREF***')";
$fql_obj = json_decode($fql_query, true);

Facebook FQL for retrieving a reply to a comment box comment

I'm using the Facebook comment box plugin and am also subscribing the comment.create JavaScript event so that I can retrieve the details of the comment from Facebook using FQL and store that comment data in my application's database.
So far, when I receive the ID and href of the new comment (passed into the comment.create event handler), I am able to use the following FQL to retrieve the details of that comment:
SELECT object_id, post_id, fromid, time, text, username
FROM comment
WHERE post_fbid='*** EVENT COMMENT_ID ***' AND object_id
IN (SELECT comments_fbid FROM link_stat WHERE url='*** EVENT HREF ***')
All of this works great.
The problem occurs when a user replies to a comment. In this case, the query above fails to retrieve the comment.
I've done some digging around and have found that the Facebook 'comment' table apparently has a 'comments' field (or relationship, not sure) that contains the replies to the comment. You can even use the following query to retrieve all of the replies to a comment:
SELECT comments
FROM comment
WHERE post_fbid='*** EVENT COMMENT_ID ***' AND object_id
IN (SELECT comments_fbid FROM link_stat WHERE url='*** EVENT HREF ***')
After tinkering with the FQL test console, I can see that the replies are being added to this 'comments' field. However, rather than trying to retrieve ALL of the replies, I'm trying to lookup the specific one whose ID I received in the comment.create event handler. The problem is, since 'comments' appears to be a field rather than a linked table, I don't think I can query it.
Anyone else run into this? Any advice would be greatly appreciated.
Thanks.
Try this:
SELECT text, time, id, likes, fromid, comments FROM comment WHERE is_private = 0 AND
object_id IN (SELECT comments_fbid FROM link_stat WHERE url ='YOUR_URL') or
object_id in (select post_fbid from comment where object_id in (select comments_fbid from link_stat where url ='YOUR_URL'))
ORDER BY time DESC limit 0,10

Getting user likes of stream items via FQL (posts, comments, pictures, links, etc)

I need assistance in getting user likes of stream items via FQL. I've got some of the likes coming back, but cannot figure out how to get others. For the access_token, every permission is granted.
Let me show you what I've been able to do:
postings I've liked on Page feeds:
fql?q=Select post_id, source_id, message FROM stream where source_id in (SELECT target_id FROM connection WHERE source_id=me() and is_following=1) AND likes.user_likes=1 LIMIT 10
Note: This worked as of mid Dec 2011 when the original question was posted. Now (mid Feb 2012) it is no longer returning anything liked stream content from a page.
postings I've liked of posts that I posted:
fql?q=Select post_id, source_id, message FROM stream where source_id=me() AND likes.user_likes=1 LIMIT 10
Here's what I'm missing
postings I've liked on friends' walls:
fql?q=Select post_id, source_id, message FROM stream where source_id in (SELECT uid1 FROM friend WHERE uid2=me()) AND likes.user_likes=1 & LIMIT 5000
postings I've liked on events' walls:
????
postings I've liked on groups' walls:
????
Here's what I've come up with, as of the time of posting (10-22-2012):
For friends/subscribedto/pages items:
SELECT likes, post_id, actor_id, target_id, message
FROM stream
WHERE source_id IN (SELECT target_id FROM connection WHERE source_id=me())
AND likes.user_likes=1
OR
From 'like' table:
SELECT user_id, object_id, post_id
FROM like
WHERE user_id=me()
But post_id is always null and object_id doesn't exist sometimes when queried via the graph api (i.e. graph.facebook.com/OBJECT_ID )
For links/external objects - There is no direct way to get the facebook post details from this, but it returns a lot of results. Maybe with another query / multiquery looking for these urls in the stream or link tables.
SELECT url
FROM url_like
WHERE user_id=me()
I found a solution using the Open Graph API. Hope this will help you also?
To perform this action you need the users read_stream permission.
Please let me know if my solution works for your requirements.
Because FQL will not be longer supported than V2.0, I would prefer using Open Graph API over FQL.
/*
*
* Count my_user_id likes in wall of user "123"
*
* ex: url = /123/posts
*
* setTimeout to avoid exceed api level rate limit, code 613
*/
function findMyLikes(url,my_user_id,count,callback) {
console.log(url);
FB.api(url, function (response) {
if (response.data) {
response.data.forEach(function (post) {
//console.log(post);
if (post.likes) {
post.likes.data.forEach(function (like) {
if (like.id == my_user_id) {
count++;
}
});
}
});
}
if (response.paging && response.paging.next) {
setTimeout(function() {findMyLikes(response.paging.next,my_user_id,count,callback)},1000);
} else {
callback(count);
}
});
};
I noticed that this solution may take some time, if your are analyzing very long feeds.
For this issue I have still an open question pending : Getting all likes from a specific user on a news wall with fewer graph API calls
https://codereview.stackexchange.com/q/58270/50013?sem=2
#Jeff Sherlock, a partner engineer at Facebook, says here that 'you cannot pull all of the likes of a person using the fb platform. We limit it to actors, movies, sports teams, etc. for privacy reasons.' I know it doesn't make much sense since you can query all kinds of other stuff with the Facebook API. I would suggest you pic Ashton Kutcher and try to query on his like table... Wait, you need his permission ; ]
The problem is that the like table returns a blank post_id for everything. However, it does return an object_id for your likes.
You can put all these object_ids in a comma separated string, then submit a graph API call with ?ids=objectid1,objectid2,objectid3 etc.
This will then return all the objects that it finds. This way you can get the likes for stream items.
It seems to go about 4 weeks back. I can't seem to make it go any further back than this.
As an aside, one thing you will find is that liked comments are also returned as object_ids in the like table. However, there does not appear to be any way at all to find out the object details of these object_ids. Bit of mystery with these ones.
If you read the like table documentation, post_id field has a note which reads :
These post IDs must be queried from the stream FQL table.
Hence when you compare post_id like post_id<>"", it won't return you anything as default result contains blank post_ids. And it seems when you run below query :
SELECT user_id, object_id, post_id
FROM like
WHERE user_id=me()
It returns the pages liked by user and some other stuff but not the feed posts.
As you already want to get likes from stream table, you just want to get post_id from stream table. To get post_id of NewsFeed for a given day, you might want to try below query.
SELECT post_id
FROM stream
WHERE filter_key IN (
SELECT filter_key
FROM stream_filter
WHERE uid=me()
AND type='newsfeed'
)
AND is_hidden = 0
AND description<>''
You might want to use Limit and Created_time fields to get more no. of posts. And once you use above query in Multi-query to get likes for the user, you'll definitely get likes for a given day.
SELECT post_id, actor_id, message, type, permalink, attachment, likes,
comments, description, updated_time, created_time
FROM stream
WHERE filter_key in (
SELECT filter_key
FROM stream_filter
WHERE uid=me() AND type='newsfeed'
)
just change type on your requirement
This is not possible with the GraphAPI. The GraphAPI will allow you to see the pages that a user has liked with /me/likes, but it will not give you a list of all the items posted to the user's wall that they haved liked.
You can see details on this in the Facebook Documentation.
I have no experience with FQL as listed in your question, but a Stack Overflow question seems to provide an answer to your question.
See: Facebook API - "All my likes" query
Worked perfectly in testing.