skip to Main Content

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


  1. 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:

    fb_events = graph.get_object(fb_venue['url_listings'], 
        {since: from_date, until: to_date})
    

    …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

    Login or Signup to reply.
  2. 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 to
    permissions.

    add user_events to the list of scope that you are permitting from user.

    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 the get_object function, You can use until and since but they should be in A Unix timestamp look at this to see the needed date format, hope this would help.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search