Facebook - How to get the comments of a fb:comment - facebook

I need to get the comments posted on a fb:comments widget. Here is what I've tried:
http://graph.facebook.com/comments?id={{ url_of_the_page }} - Returns an empty list
Executing the following FQL
SELECT post_fbid, fromid, object_id, text, time
FROM comment
WHERE object_id IN
(SELECT comments_fbid
FROM link_stat
WHERE url ={{ page_url }}) - Return an empty response with the fql header
I'm beginning to think that this is not possible. Am I missing something or is this indeed not possible?

That is how you do it. What is the url you are trying? For example, this random Techcrunch article works in the same way as you describe:
http://graph.facebook.com/comments?id=http://techcrunch.com/2011/09/20/digg-experiments-with-topic-newsrooms-aggregates-news-by-most-meaningful-stories/

Related

Facebook API reading comments attachments

My trying to find a way to read all comments attachments.
This is what my status update looks like: http://screencast.com/t/sXqOzA3OsF
There's an attachment with the message "Mitt Bidrag".
I'm getting the correct json-stream using "me/feed" but it's missing information about the attachment.
This is what the feed looks like: http://screencast.com/t/sEL2iEsVOWu
I've tried a bunch of FQL-commands with the comment/attachment-table but I'm only retreiving.
Here are some examples of what I've tried:
- SELECT id, text, time, fromid FROM comment WHERE object_id='100002055769071_617700241641829' AND parent_id='0'
- SELECT id, text, time, fromid FROM comment WHERE object_id='617700241641829_653988868012966' AND parent_id='0'
- SELECT post_id, user_id FROM like WHERE post_id = "617700241641829_653988868012966"
- SELECT message FROM stream WHERE post_id = "617700241641829_653988868012966"
Response is: {
"data": [
]
}
Anyone have a solution?
Thanks a lot.
Try use this FQL query to get the comment details based on post ID:
SELECT id, text, post_id, comment_count, attachment.media.image.src
FROM comment
WHERE post_id = "617700241641829_653988868012966"
Please refer Comment-columns for more others comment details that you need to use.
Hope this can help to solve your problem.
This solved it:
SELECT attachment FROM comment WHERE id="617700241641829_653988868012966"

comment.create event gives me an useless comment id because I cannot make a query with it [duplicate]

I am using Facebook comment box plugin:
<fb:comments href="${myPageUrl}" num_posts="20" width="630"></fb:comments>
Every thing is working fine. The problem is that I want to store the comment posted into my database. Is there any way to fetch the text posted on the comment box.
I am using the following js to catch comment-create event.
FB.Event.subscribe('comment.create', function(response) {
alert(response.commentID)
});
I'm getting some commentId from this but I don't know how to fetch the exact comment posted on a particular comment-create event.
Coomie: Actually whenever a comment is posted, I catch the event thru 'comment.create'. I was able to catch the event but I was wondering how to get the comment(text) posted at that particular event. Like event.text or event.comment but there was no direct method found
So, now I am manipulating it with fql. Which is somewhat similar to you example. First retrieving the whole list and then selecting the top one.
My sample code is below:
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 ='${PageUrl}') order by time desc limit 1"
},
function(response) {
var feed = response[0];
alert(feed.text)
});
});
So this method is giving me exactly the same result I want.
I don't have the complete answer but this should get you on your way.
You can use the facebook graph api to extract information about an open graph id (an open graph id is FB's way of identifying a person, website, application or URL). Eg. this page:
http://www.inhousegroup.com.au/newsroom/23-best-practice-for-advanced-seo/ (the place that fired me)
uses a comment box. The web page has an open id of 10150441190653416. So when you comment on this page facebook sees your comment as a wall post on that page's "wall".
Using the graph api, you can get some JSON info about the page here:
http:/graph.facebook.com/10150441190653416
And you can get the posts from this address:
http://graph.facebook.com/10150441190653416/posts
But you'll have to get an access token.
Then you just have to import the posts on save and compare your db to the JSON and add records as neccessary.
Good luck!
FB.Event.subscribe('comment.create', function(response) {
var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
FB.Data.waitOn([commentQuery], function () {
text = commentQuery.value[0].text;
// Use your preferred way to inform the server to save comment
$.post( 'http://example.com/comment', text )
});
});

Facebook Graph API - get a photos album ID

I'm writing an application that uploads a photo to facebook. I'm not supplying an album ID so an album is created on behalf of my app.
My question is: how do I get the album ID the photo was uploaded to?
When I GET the the photo information the album isn't present in the JSON which was my hope.
Jimmy Sawczuk's answer is close, but doesn't work because FQL Photo table columns aid and pid are Rest/FQL API ids, not Graph API ids.
Fortunately the object_id and album_object_id columns in this table are indexable (contrary to the documentation) so this should give you both Rest/FQL & Graph ids for the album:
select aid, album_object_id from photo where object_id = ${GRAPH_PHOTO_ID}
In general object_id fields in Rest/FQL API responses are Graph API id (except for photo notifications, where it's the Rest/FQL id).
Re HonkyHonk's answer: not all photo link urls have a set parameter; in this case I think you can find the Rest/FQL API photo id from its other parameters, and then use Rest/FQL API to get the album id:
For users with 32-bit user-ids: calculate (id << 32) | pid
eg for http://www.facebook.com/photo.php?pid=7518353&id=549683637 this gives 2360873244068853905
Otherwise concatenate id, _ and pid
eg for http://www.facebook.com/photo.php?pid=155052&id=100002937903251 this gives 100002937903251_155052
It would help a lot if Facebook could document something about the two types of ids. Also the Graph API Photo schema should include the album's Graph API id.
This is the easy way to get it :
This issue has been bugging me for a while as well, but I think I have cracked the nut.
The album ID is hidden in the link value, so if you have a photo-post object from the Graph API, you can retrieve the Album ID like this:
NSString *link = [item valueForKey:#"link"];
NSString *album_id = nil;
NSRange fRange = [link rangeOfString:#"set=a."];
if(fRange.location != NSNotFound) {
NSInteger firstPos = fRange.location + 6;
NSInteger endPos = [link rangeOfString:#"." options:NSLiteralSearch range:NSMakeRange(firstPos, 25)].location;
album_id = [[link substringWithRange:NSMakeRange(firstPos, endPos - firstPos)] copy];
}
It could probably all be stripped down to one line of code, but I think this is more readable.
For getting the album information use:
[facebook requestWithGraphPath:album_id andDelegate:delegate];
For getting all the photos in an album use:
[facebook requestWithGraphPath:[NSString stringWithFormat:#"%#/photos", album_id] andDelegate:delegate];
Hope this can help someone.
If I'm understanding you correctly, you have the photo ID but need the album ID. You could try using the photo FQL table with the following query:
SELECT aid, pid FROM photo WHERE pid = '<your photo id>'
Long, clunky, but theoretically valid way:
http://graph.facebook.com/userid/albumswill get you a list of all the albums the user lets you see, then you can search the album objects (api here) for created_times that match the time you created the album, which you can store when you create the album.
This is almost certainly a horrible way to do it, but it should work.
Richard Barnett's solution works well for me, I use this as an FQL query through the Graph API to get a JSON response like I would for any other Graph API query:
https://graph.facebook.com/fql?q=select+album_object_id+FROM+photo+WHERE+object_id='[PHOTOID]'
This returns:
{
"data": [
{
"album_object_id": "10150531092908837"
}
]
}
Then you can access the album ID using:
<?php
$strPhotoAlbumID = $objFacebookAPI->data[0]->album_object_id;
?>
This is the cleanest solution i've found as Facebook constantly change the format of their photo and album URLs so parsing these with RegEx wont work as a long term fix.
I ended up just using the legacy REST api since the album ID is passed with the link to the image in the server response. I then used a regex to pull the id out.
Not the best solution and I wouldn't recommend it but I feel its better than adding another several server requests to the code.
function get_album_id_by_album_name($album_name){//return array of data
$fql = 'SELECT aid, owner, name, object_id FROM album WHERE owner=me() and name="'.$album_name.'"';
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $this->facebook->api($param);
return $fqlResult;
}
String albumID = "https://www.facebook.com/photo.php?fbid=192570127478130&set=a.135556629846147.24342.100001754323389&type=1";
albumID = albumID.split("&set=a.")[1];
albumID = albumID.split("\\.")[0];
System.out.println(albumID);

Determine Object_ID of a URL to use with the Facebook Open Graph

I am trying to learn how to use the Facebook Open Graph API and have a question on how to determine the object_id of my site. I need this object_id so that I can do other queries, such as I want to get a list of users who have liked my site within a given time period.
Based on other Stackoverflow questions I have seen that I should be able to run this query to get the object_id
select id from object_url where url in ('www.bubbasgameroom.com', 'bubbasgameroom.com')
When I run that query it comes back with an empty result. When I run the following query, I see that my page has been liked 21 times
select total_count from link_stat where url in ('www.bubbasgameroom.com', 'bubbasgameroom.com')
What am I missing here? Any help will be greatly appreciated.
Thanks!
Most likely the url should be identical to the og:url meta tag if used on your website. Also you need to append the http:// part for it to work. For example this would work:
SELECT url,site,id
FROM object_url
WHERE url IN (
'http://developers.facebook.com',
'http://www.imdb.com/'
)
Result:
[
{
"url": "http://developers.facebook.com",
"site": "developers.facebook.com",
"id": 113167538713703
},
{
"url": "http://www.imdb.com/",
"site": "www.imdb.com",
"id": 6903354771
}
]
But this doesn't:
SELECT url,site,id
FROM object_url
WHERE url IN (
'developers.facebook.com',
'www.imdb.com/'
)

Facebook API: a strange query error 601

I get this error while trying to obtain the number of shares and likes of the particular link on Facebook:
{
"error_code":601,"error_msg":"
Parser error: unexpected ''' at position 56.",
"request_args":
[{"key":"method","value":"fql.query"},
{"key":"format","value":"json"},
{"key":"query","value":"SELECT share_count, like_count FROM link_stat WHERE
url='http://www.lrinka.lt/index.php?act=main"},
{"key":"item_id","value":"5963'"}]
}
The link: http://www.lrinka.lt/index.php?act=main&item_id=5963
The API call: https://api.facebook.com/method/fql.query?format=json&query=SELECT%20share_count,%20like_count%20FROM%20link_stat%20WHERE%20url=%27http://www.lrinka.lt/index.php?act=main&item_id=5963%27
Everything works fine with other links.
You are not closing the url parameter field correctly, missing ' at the end of the URL.
Also no need for the "slashes", try the following in the fql.query console:
SELECT share_count, like_count FROM link_stat WHERE url='http:\/\/www.lrinka.lt\/index.php?act=main
Would return the same error, and this:
SELECT share_count, like_count FROM link_stat WHERE url='http:\/\/www.lrinka.lt\/index.php?act=main'
Is valid but would return zero, and finally this:
SELECT share_count, like_count FROM link_stat WHERE url='http:\\www.lrinka.lt\index.php?act=main'
Would return the result expected.
EDIT:
Based on your comment, you are trying to call https://api.facebook.com/method/fql.query?query=QUERY with the format parameter set to json..so you need to encode the query, I used encodeURI:
https://api.facebook.com/method/fql.query?format=json&query=SELECT%20share_count,%20like_count%20FROM%20link_stat%20WHERE%20url='http:%5Cwww.lrinka.ltindex.php?act=main'