How do I pull the name of the user that posts to our page wall? - facebook

I have looked through and couldn't find the answer on here...
We are doing a promotional giveaway and have a ton of addresses of people trying to get free stuff. What we want to do is give the people who post most on our facebook wall a better chance of winning.
So I am trying to set something up (I'm guessing using Graphs API/FQL) that will pull the name of the person who posted to our wall or commented on one of our posts. If I can get a list like this, I have enough php/mysql experience that I can create the code to compare the name with the database and weight their entry.
Does anyone have a simple explanation on the code to pull just the names of the people who posted each time?
Thank you so much for your help!!

Using FQL you can get the ids of those who posted on your page wall:
SELECT post_id, actor_id
FROM stream
WHERE source_id = "PAGE_ID"
and those who commented on posts:
SELECT post_id, fromid
FROM comment
WHERE post_id = "POST_ID"
You also should be able to combine them:
SELECT post_id, fromid
FROM comment
WHERE post_id IN (SELECT post_id
FROM stream
WHERE source_id = "PAGE_ID")
Once you have the ids you can simply query: https://graph.facebook.com/USER_ID and get the name of the user.
If you have too many and don't want to issue a request per one you might want to consider using the Batch Requests option.

Related

Getting 'pic-square' from user posts on the news feed using Facebook Graph API

I'm trying to get the 50 x 50 profile picture for user posts on the news feed. It's easy to do this for likes and comments on posts but I can't figure out how to do it for the initial posts.I also want to limit the query so that I only get results from "people" not "pages" and I only want unique results. In other words if a user appears twice on the feed I only need their picture once. I've played with the Graph API Explorer extensively and have looked all over the forums, here, as well as the documentation on the Facebook developers site. I would think this would be a common request so I'm not sure why it's been so hard to find.My guess is that the syntax of the query would look something like this. Although this query doesn't work in the explorer.
me/home/?fields=from.id.fields(pic_square),from&profile_type=user
Well after a lot of research and trial and error with FQL I figured it out. It's a series of nested queries and it returns an array with the urls of the pic-square images of the users whose posts appear in your news feed. The FQL query looks like this:
SELECT pic_square FROM user WHERE uid IN (SELECT actor_id FROM stream WHERE filter_key IN (SELECT filter_key FROM stream_filter WHERE uid=me()))
I was not able to differentiate between user and page profile pics.

How to retrieve user image in FQL selected comments from stream?

I'm building a simple FQL module to pull in comments from any Facebook fan page.
Getting the post_id, message, actor_id seems pretty straightforward.
However the stream documentation does not seem to indicate any way to get the avatar and name.
What I'm doing is:
SELECT post_id, message, actor_id
FROM stream
WHERE source_id = 125938460770575
Which returns FB Id, comments and the post itself.
I need the user info as well to go along with this.
The obvious solution is to just to an extra FQL API call for every single FB Id (actor_id) that appears to get this info, but I assume there is a better way to do it.
Can I please get some hints on how to do this?
You can use an FQL Multi-Query to achieve that – you “name” your queries, and then the second query can refer to values (in this case the user ids) the first query fetched.
https://developers.facebook.com/docs/technical-guides/fql/#multi has an example that is very similar to what you want, except for that it looks up the user names and pics for users attending an event – but to rewrite that for what you want should be no big deal.
Afterwards you only have to match the ids you get for the users commenting on something with the ids from the second query while processing/displaying the data.
The obvious solution is to just to an extra FQL api call for every single fb id (actor_id) that appears to get this info, but I assume there is a better way to do it.
Yes of course, you can do it like this-
SELECT uid,
pic,
first_name,
last_name
FROM user
WHERE uid IN(
SELECT post_id,
message,
actor_id
FROM stream
WHERE source_id = 125938460770575)
Fetch any detail of the user

Facebook FQL query to return all comments against an application [duplicate]

We use the facebook comment plugin to have comments on our site.
To moderate those, we use this tool: https://developers.facebook.com/tools/comments
However, we want to build our own tool to moderate those comments, and integrate it to our existing software.
I can't find a proper way of doing this. the only way I found out now after hours of research is this FQL query:
select post_fbid, fromid, object_id, text, time from comment where object_id in (select comments_fbid from link_stat where url ='URL_HERE')
That doesn't work because we have thousands of different URL's and I cant query each of them every time to see if there are any new comments.
I need a way to get all (new) comments by just enter our app_id, domain or something like that
How can I do this?
I'm considering doing the same thing- grabbing all user posts for my application. I'm assuming it's a similar task.
For given user, I will scroll through feed and home looking for app posts. For you, you'd go:
`home?fields=comments`
`feed?fields=comments`
And check for "type" and "id" to match your application.
This code queries for all comments xids used by your application:
https://graph.facebook.com/fql?q=SELECT fromid, text, id, time, username, xid, object_id FROM comment WHERE xid IN (SELECT xid FROM comments_info WHERE app_id = {0}) ORDER BY time desc&access_token={1}&format=json

List of people who shared on facebook

I've been scouring the docs for a while now and can't seem to find a way to accomplish this. The information is available publicly (on a facebook page ... the link says "View all # shares") but I can't seem to find a way to access this info either via FQL or the graph API.
I know I can get a list of likes for a given post:
https://graph.facebook.com/87236249496_134765166623967/likes
The goal is to get a list of people who've shared -- but there doesn't seem to be the same sort of thing for shares. Am I missing something?
You can do it via "graph.facebook.com/OBJECT_ID/sharedposts" connection:
I figure it out this connection via metadata=1 parameter:
Go to... http://www.facebook.com/ajax/shares/view/?target_fbid=10154612868272801&__a=1
10154612868272801 is Facebook story ID, __a stands for asynchronous.
You will see large amount of text/JSON, it is basically HTML & JS for little popup window. There is portion of text like hovercard.php?id=# where # is Facebook user ID, using preg_match_all you then get all of the user ID's who shared that post.
Eg: 100000541151971 (Eric) and 9204448 (Courtney)...
Unfortunately, you must be logged into Facebook to do first step, figure it out :)
I think you can get the share_count from stream table by FQL query just like
SELECT type, source_id, share_count, permalink, description, post_id, actor_id, target_id, message , share_count
FROM stream
WHERE filter_key = 'others' and post_id = '87236249496_134765166623967'
you can test it https://developers.facebook.com/tools/explorer/
Note: you have to take the read_stream permissions as explained here
Tye this link: https://graph.facebook.com/134765166623967/sharedposts (with a valid access_token)
The id in the link is the wallpost id (87236249496_134765166623967) minus the page id (87236249496) and minus the underscore.
You'll also need the read_stream permission
I know you're looking to get at shares through the post_id, but can you settle for finding shares by page_id instead of post_id?
If you can, then you can use the following FQL to get the data you're looking for.
SELECT via_id, created_time, owner_comment
FROM link
WHERE owner = me()
You can then compare via_id against the posts author (page ID) to determine if this share came from the post author in question.
Unfortunately, there seems to be a bug with the data return where some of the via_ids come back as 0. There is a ticket in with Facebook which, at the time of this post, has been open for three weeks at medium priority. I have no idea if this issue is specific to my app or affects everyone, but that query might get you what you want.

How to retrieve the comment and LIKE count of a facebook post

I am trying to execute following FQL and the result is always an empty XML
https://api.facebook.com/method/fql.query?query=SELECT post_id, comments.count FROM stream where post_id = 167995709886177
<fql_query_response list="true"/>
This is the post and it has lot of comments and LIKEs
http://www.facebook.com/ryanleslie/posts/167995709886177
Please help
#Anz just go through facebook developer section. all your doubt solve their
You need to use a URL like this:
https://graph.facebook.com/100002725117360_142921995808637?access_token=154407880175|16a3d55d6e4be468d6a131bc.1-100002735407608|IhahmvIUsur7GuZ45rxRj3boXtE
The bolded id (100002725117360_142921995808637) is the ID of the post. The part before the underscore is the user id of the person on whose wall the post appears, and the part after is probably the ID you are using in the example.
This will give you everything you need -- comments, likes, etc. If you want even narrower info, you can do that with URLs like this:
https://graph.facebook.com/100002725117360_142921995808637/likes?access_token=154407880175|16a3d55d6e4be468d6a131bc.1-100002735407608|IhahmvIUsur7GuZ45rxRj3boXtE
Note: this is a test user account, so I'm not exposing anyone's private info here.