Getting all my events via Facebook iOS SDK

喜欢而已 提交于 2019-12-21 07:34:39

问题


In my iOS app, I get an access token using the following code:

    [self.facebook authorize:[NSArray arrayWithObjects:@"user_events",
@"friends_events",  nil]];

I then request my events with the following code:

[self.facebook requestWithGraphPath:@"me/events" andDelegate:friendsVC];

But as a response, I only get events I have RSVP'd to. I would like to get all my events including those I have not RSVP'd to.

Any ideas?


回答1:


You can get list of events regardless of their RSVP status with next FQL query:

SELECT eid, name, venue, location, start_time FROM event WHERE eid IN (
  SELECT eid from event_member WHERE uid = me()
)

This will not return RSVP status for each event but just events details. You may wish to use Batch Requests to get both details of events and rsvp_status with same query.

https://graph.facebook.com/?method=post&batch=[
  {
    "name":"rsvp",
    "relative_url":"fql?q=SELECT+eid,rsvp_status+FROM+event_member+WHERE+uid=me()",
    "omit_response_on_success":false
  },
  {
    "relative_url":"?ids={result=rsvp:$.data.*.eid}"
  }
]

See event and event_member table documentation for details on other fields you may wish to retrieve.

Notes:

Starting July 5th, an access token will be required to access even public events.




回答2:


The request

/me/events

only gives you the events a user is (maybe) planning to attend. The response doesn't include events which the user has been invited to (but not responded to), or declined.

There are other requests that may be of help:

You can check if a user has been invited to an event like so:

/EVENT_ID/invited/USER_ID

RSVP status can be checked by event:

/EVENT_ID/attending

/EVENT_ID/maybe

/EVENT_ID/declined

/EVENT_ID/invited

where each request returns a list of users with the queried RSVP status.




回答3:


I think you may get events by fql query. You need to try this.

Also see this How-To: Use the Graph API to Manage Events.

You will need to HTTP Get the following from the Graph API:

fql?q=SELECT uid,eid,rsvp_status FROM event_member WHERE uid = me()

You can get back all statuses from that call.

{
  "data": [
    {
      "uid": "723020003",
      "eid": "19935786340002",
      "rsvp_status": "not_replied"
    },
    {
      "uid": "723020003",
      "eid": "234524000290351",
      "rsvp_status": "attending"
    },
    {
      "uid": "723020003",
      "eid": "210091000081240",
      "rsvp_status": "declined"
    },
    {
      "uid": "723020003",
      "eid": "210091000341240",
      "rsvp_status": "unsure"
    }
  ]
}



回答4:


This isn't a complete solution, and this may not work, but see if it's possible to get access to the iCal feed of a user's Facebook events. I subscribe to my iCal feed, and I noticed that all events, even new ones that I have yet to RSVP to are included in the feed.

Something to try anyway!




回答5:


Use /me/events for getting the events the user has responded to, and /me/events/not_replied for the others.

For example (assuming you have created a session):

[FBRequestConnection startWithGraphPath:@"/me/events/not_replied" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
    FBGraphObject* data = (FBGraphObject*)result;
    NSMutableArray* array = [data objectForKey:@"data"];

    //parse data etc..
}];

See https://developers.facebook.com/docs/graph-api/reference/v2.0/user/events/ for more info.



来源:https://stackoverflow.com/questions/10635817/getting-all-my-events-via-facebook-ios-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!