I am using ruby koala facebook graph API gem to retrieve events but cant restrict the events using a date range. I seem to be getting all events (even ones which have happened). What I am trying to do is get events is the next 200 days. I am using the following (ruby) code:
Koala.config.api_version = 'v2.10'
oauth = Koala::Facebook::OAuth.new app_id, app_secret
graph = Koala::Facebook::API.new oauth.get_app_access_token
from_date = Date.today
to_date = from_date + 200
fb_events = graph.get_object( fb_venue["url_listings"] + "?time_range={"since":#{from_date}, "until":#{to_date}" )
I am then getting the events 25 at once (the facebook default limit) using ‘fb_events.next_page’ to get them all.
I seem to get getting all events, including ones is the past.
2
Answers
Are you sure that the
#get_object
method wants a query string like that? Based on the docs[1], it seems that you should pass your object ID (which I assume is in fb_venue[‘url_listings’] for you as a first arg, and then metadata in a subsequent arg as a Hash. So I’d try something like:…according to the key/nesting structure FB expects.
Edit: forgot link to docs.
[1] –
http://www.rubydoc.info/github/arsduo/koala/Koala%2FFacebook%2FGraphAPIMethods%3Aget_object
According to the doc I don’t think that you can request all the events, You can only select an event by using
/{event-id}
like this example or you can get user’s events but you will need to ask him for the permission according topermissions.
By this when user sign up using Facebook to your application it will take a permission for his events.
After that by using
graph.get_object({facebook-user-id} + '/events')
you will get 25 of his events as a default value and you can add{limit: 5}
as a second parameter to theget_object
function, You can useuntil
andsince
but they should be inA Unix timestamp
look at this to see the needed date format, hope this would help.