Facebook API get events CREATED BY friends - events

I am developing facebook app which needs to retrieve events created by some of my friends.
Standard SQL query would look like this:
NSString *fql1 = #"SELECT "
#"eid, name, tagline, id, pic_small,host, description, start_time, creator "
#"FROM "
#"event "
#"WHERE "
#"creator = 1111111111 OR creator = 2222222222 OR creator = 333333333";
Facebook allows only to filter tables by indexed fields (which is eid in this table). I assume I could to construct multiquery. Anyone could help with it? I spent some time googling it with no look. I need only one query so learning whole fbl for this has no sense for me at the moment.
BTW: there is a function events.get - you can filter by uid (documentation says):
parameter: uid - Filters by events associated with a
user with this uid.
ASSOCIATED In what sense? are those creator's uids?, invited, attending or maybe? Why facebook documentation is so frustrating?
When I try events.get with uid parameter it returns result with different creators ids than uid parameter.
Graph API function: uid/events returns events user has been invited to, attended or other status but NOT necessarily created by him.
What am I missing here? I granted necessary permissions to my application, it connects, gets friend's event lists but not the events I want.
Seems so simple but I con not find straight-forward solution.
I'd appreciate any help.

You can do something like this:
SELECT
eid, name, tagline, pic_small,host, description, start_time, creator
FROM
event
WHERE
eid IN (
SELECT
eid
FROM
event_member
WHERE
uid=111 OR uid=222) AND
(creator=111 OR creator=222)
Basically this says get the events user 111 or 222 is a member of and of those, only return the ones they've created. Because eid is an indexable field, FQL is okay with this, and is happy to do the additional (creator=111) trimming for you.

Related

Facebook graph api Events and Venue Information, sometimes it only returns venue id when the event was created in a known venue

I'm creating an app in Titanium that uses the Facebook Graph API to get all the users events, however, the venue information, it only brought to me, after I was very specific about the field, and some times, a lot of the times, when the Event was created in a known location, it only brings the venue_id, and when I query the venue(via http://graph.facebook.com), then it gives me the venue location details, more importantly, the latitude and longitude of the thing.
Is it possible to bring the information of the venue in the same response?
Also, it only brings the events that the user is attending, is there any way to show the events recommended to him also?
Ti.Facebook.requestWithGraphPath('me/events?limit=5000&fields=id,owner,name,description,start_time,end_time,location,venue,privacy,updated_time', {}, 'GET', function(e) {
obj = JSON.parse(e.result);
Ti.API.info('Events: '+JSON.stringify(obj));
}}); // Facebook Events
Also, it only brings the events that the user is attending, is there any way to show the events recommended to him also?
Not sure what exactly you mean by “recommended” … if you mean events the user has been invited to, then you can query the FQL event_member table with the user id.
You can kind of “join” the info from the table above with the event table by selecting from that using WHERE eid IN (SELECT … FROM event_member WHERE …)
Is it possible to bring the information of the venue in the same response?
Using a multi-query you can do it, similar to as it is described here: FQL: query for event table returns venue.name instead of venue.id

Getting events that a certain profile is attending

Im trying t get some info for some events that certain profile rsvp status is attending but it retrieves blank. Maybe is something about access tolken or whatever.
This is my current fql
SELECT name, pic, start_time, end_time, location, description
FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = 100003454558689 AND rsvp_status = 'attending')
ORDER BY start_time asc
But it retrieves blank. How can I fix it?
Well your code is good, you just have to make sure you have the user's rights to get that data. So go to the facebook graph explorer, and pop in your code, but this time change the UID to me(). Why does that work?
Your access token, granted by the Facebook app, determines what user data you can see on Facebook. The Graph Explorer by default shows you your own data.
So make sure that you have the right permissions for event data. You can test it by the Acess Token drop down on the Graph explorer.
Here is a list of permissions: https://developers.facebook.com/docs/authentication/permissions/
Looks like you need "user_events"
So it might be nothing wrong with FQL, but something in the auth process. Good luck.

Querying for past events using FQL

I'm trying to access the past events of a given user. I'm using the following FQL query: SELECT eid, name, pic_square, start_time, end_time, location FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid = me() AND rsvp_status != 'declined') AND start_time < 1338974650 ORDER BY start_time DESC LIMIT 0,20 (1338974650 is supposed to be the current UNIX timestamp). This works fine. However, facebook only returns a set of 4 events in my case, whereas facebook.com displays a lot more. Why is that?
Yes. Facebook severely limits the amount of past items returned by an API call. When I visit one of my pages, I see over 75 events listed on the past events page. When I query the page's events using either FQL or Graph API, I only get 2 events. My guess is Facebook has a separate table that stores past events that isn't available via the API.
BTW, You can make your code simpler by replacing your timestamp with now().
if you query the event_member table by passing the uid, you will get all the events that were CREATED by the user. if you query the table by passing one eid, it gives you the members of the event and their rsvp statuses.
EDIT: try setting start_date > 0 as stated here it should show you ALL the events.

Retrieve Facebook Fan Names

I'm trying to grab the names of fans of a Facebook fan page that I administer. I've done some snooping around, and apparently, the FB API doesn't support that, but Facebook actually uses AJAX/JSON to populate the list. Anyways, can anyone suggest a way to make that call myself and grab the data as plain text?
Also, I've found a hack that a guy wrote in Ruby, but I am completely unfamiliar with the language.
Thanks for the help in advance!
At the current time the FQL schema would suggest that there is no way to get a collection of FANS for any given PAGE. I think they are hiding this information because they display the FANS on the page... One would think that at least the ADMIN would have privileges to see the list of users.
Anyway... I hope someone make is possible in the near future.
can you please try this and let me know :
select uid,name from user where uid in ( select uid from page_fan where uid in (select uid2 from friend where uid1 = me()) and page_id = 'Your Page Id')
I think you can get it only for the currently logged in user and his / her friends only.
If you have less than 500 fans, you can use the following url:
http://www.facebook.com/browse/?type=page_fans&page_id=13207908137&start=400
Each page will give you 100 fans. Change &start to (0, 100, 200, 300, 400) to get the first 500. If &start is >= 401, the page will be blank :(
I found that in the doc: http://developers.facebook.com/docs/reference/fql/page_fan/
uid - "The user ID who has liked the Page being queried."
SELECT first_name, last_name FROM user WHERE uid IN (SELECT uid FROM page_fan WHERE page_id = [your page id])
This should work, but I get an error trying to run this through the .net facebook api...something about the where clause not being on an indexable column, which it is.
Perhaps give that a try on your platform.
That one worked
SELECT user_id FROM like WHERE object_id="YOUR PAGE ID"

what would be a good algorithm to keep count of unread items In an online feed aggregator implementation?

Assume the database has tables for Users, Feeds, Items, and an ability to know which Items the user has already seen. I am looking for a design paradigm that can be used on the server to compute in a short amount of time [feed id, num_unread] for each feed that the user has subscribed to.
Assume plenty of users and that the feeds are getting updated periodically in the backend.
Edit: I wanted to solve the problem Nick J has brought up (see below). But I appreciate the solution posted by cletus. I am not so worried about the db queries, but want a "design paradigm" -- like keeping a watchdog process that keeps the unread counts in memory so that it can be served at any point.
I'm not sure what to tell you exactly because what you're asking is reasonably straightforward.
First off, use Google Reader as a reference for online feed aggregators/readers. And if you're trying to recreate the functionality, Google Reader has pretty much nailed it already (imho).
Google Reader works simply by storing a list of feeds. In DB terms, you'd probably have these entities
User: id, name, email, etc...
Feed: id, feed_name, feed_url
Content: id, feed_id, title, content
User Feed: id, user_id, feed_id, user_label, has_read
Unread items:
SELECT COUNT(1)
FROM user u
JOIN user_feed uf ON uf.user_id = u.id
JOIN feed f ON f.id = uf.feed_id
WHERE has_read = 0
Unread items by feed:
SELECT feed_id, feed_name, COUNT(1)
FROM user u
JOIN user_feed uf ON uf.user_id = u.id
JOIN feed f ON f.id = uf.feed_id
WHERE has_read = 0
GROUP BY feed_id, feed_name
And then you just need some mechanism for marking items as read. In Google Reader's case, there are just AJAX calls triggered by mouseover events with additional links to mark everything as read, leave an item marked as unread and so on.

Resources