Why do null values get returned from the page_fan table? - facebook-fql

Using the Facebook FQL query, I'm getting Null values returned in the created_time column. Is there a particular reason as to why there is no created_time values for certain facebook ids?
Here's my query, insert your own access_token.
https://graph.facebook.com/fql?q=select+uid,page_id,created_time+from+page_fan+where+page_id+in+(8576093908)+and+uid+in+(114385755252085,130258467128954)&access_token=insert_access_token

It seems Facebook sought it not necessary to provide the created_time for pages
130258467128954 is a page
114385755252085 I think is a page as well, from some Googling it seemed to be the old DailyMotion USA page
In both cases created_time will not be returned. The correct scenario will be to return the time for the session user.

Related

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

How to display the last post of a facebook page on my webpage

I've got a facebook page which is publicly accessible. On my website I'd like to display the last post made by this page.
I made a script which uses the facebook php-api and FQL to retrieve the events from the page. But I just can't figure out how to construct a FQL which displays the latest posts from my page. I've seen the stream table and thought I should use it like this:
SELECT created_time,
likes, message, post_id, share_count, type
FROM
stream
WHERE
actor_id = {$page}
LIMIT 5
But that results in the fact I need a Starred/Indexable column. Fair enough, but I can't figure out which starred column to use.
Anybody?
You should use: source_id instead of actor_id

Facebook API not returning all photos on a page

I'm trying to grab all photos posted by other users on a page, but for some reason facebook seems to skip seemingly random photos. I'm not sure if it was happening a few days ago, but if it was I didn't notice it. Here's the FQL Query I'm using:
SELECT post_id, actor_id, created_time, permalink,
message, attachment,
comments.count
FROM stream
WHERE source_id=me()
AND filter_key='others'
AND attachment.fb_object_type='photo'
AND created_time > #{Time.now.to_i - 60*60*24*5}
ORDER BY updated_time DESC
LIMIT 0, 500
Please excuse the ruby time method in there - it works without that line, even in the api explorer. Also, the API token is for the page, so the me() method works properly. It seems to skip random photos, even though they are all public and should be returned. Is this a bug or is there something wrong with the query? If I could do this in the graph API instead, I would love to know how.

Get wall posts made through my Facebook application using FB's API

I made a Facebook Application that people use to share links from my webpage to their walls, and now I need to get back a list of the posts made through it during a pediod of time (e.g. from Sep. 4th to Sep. 10th), incluiding their Post IDs.
I am aware that I could save that information at the moment of its publication, but I need some old data that I didn't save that way.
I have tried using FQL, but that requieres to indicate the source_id (Facebook ID of the user's wall where the post is on), which I am not able to know.
The Graph API object for my application doesn't seem to help either, since it doesn't have a connection for the posts made through it.
Any help would be really apreciated, even just a sign in the right direction.
As suggested, prompt the user for read_stream permissions, and then I'd suggest to take the fql route:
SELECT post_id, actor_id, target_id, message
FROM stream
WHERE attribution=[your app name]
AND created_time > [since]
AND created_time < [until]
AND filter_key in (SELECT filter_key
FROM stream_filter
WHERE uid=me() AND type='newsfeed')
It's not likely to be an issue, but be aware that there's a limit in the number of items returned, so if your time span is wide and your users posted a lot, you may have to play with the [until] and [since] a bit more and make several calls to retrieve everything.
Also take a look at the documentation for more information about fields you can query: http://developers.facebook.com/docs/reference/fql/stream/
Prompt the user for read_stream permissions and then query /me/statuses and look for updates from your application.

Facebook Graph API: How to filter home & feed by application?

The Facebook Graph API lets you grab a JSON representation of home (News Feed) & feed (Wall).
How do I just get the posts made by my Facebook app?
Facebook has added support to filter me/home posts without using FQL by passing the filter parameter.
For example to get just photos you can do:
me/home?filter=app_2305272732
Full documentation is here: http://developers.facebook.com/docs/reference/api/user/#home
You can now run Facebook Query Language (FQL) queries using the Facebook Graph API (base URL: https://graph.facebook.com).
Let's say your application is Twitter. Twitter's Facebook application ID is 2231777543.
I came up with the FQL queries below with the help of #danontheline's answer and by carefully reading Facebook's documentation on FQL stream & FQL stream_filter.
The following excerpt is particularly pertinent:
If you specify a filter_key from the stream_filter FQL table or
multiple users, results returned will behave like the user's homepage
news feed. If only one user is specified as the source_id, you will
receive the profile view of the user or page. You can filter these
profile view posts by specifying filter_key 'others' (return only
posts that are by someone other than the specified user) or 'owner'
(return only posts made by the specified user). The profile view,
unlike the homepage view, returns older data from our databases. In
the case of a Page, the profile view also includes posts by fans.
Twitter Tweets on Your Facebook News Feed
GET /fql?q=SELECT post_id, actor_id, message, app_id, attribution FROM stream WHERE filter_key = 'app_2231777543'
Twitter Tweets on Your Facebook Wall
GET /fql?q=SELECT post_id, actor_id, message, app_id, attribution FROM stream WHERE source_id = me() AND app_id = '2231777543' LIMIT 1000
Running these queries with the Facebook Graph API Explorer returns Facebook Graph API post objects (The result set will differ depending on access_token, privacy, etc.). You can find out more about each post by adding other columns of the stream table to the queries above and/or by simply making another Graph API request to GET /{post_id} for eache post_id returned by the FQL stream queries above.
Afaik thats not possible with just the Graph API. But you can just use a FQL statement to retrieve the wall/feed, too. With this technique you are able to resrict it to the posts made by one actor_id (which should be your app ID in this case):
SELECT post_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') AND is_hidden = 0 AND actor_id = 'MattDiPasqualesAppID'
Thing here is that it won't return a JSON, but a XML representation of the result. With phps DOM class you are easily able to convert it into a JSON format or any other representation you want to have of the result!
As you might be handling the whole thing with PHP anyway, you also could just take the json array, parse it into an array and filter the array with keys of your appID.