开发者

Checking for event-rsvp status and showing disabled/enabled RSVP-button

开发者 https://www.devze.com 2023-04-02 08:50 出处:网络
I\'m still a bit unsure how I would find this in the documentation, but I\'d like to check whether the logged-in user has RSVP\'ed to an fb-event or not, and show the \"I\'m attending\" button dependi

I'm still a bit unsure how I would find this in the documentation, but I'd like to check whether the logged-in user has RSVP'ed to an fb-event or not, and show the "I'm attending" button depending on that... I've already got the login-button hooked up and the proper permissions (user_events and rsvp_event), just not sure how to go about 开发者_Go百科this using the JS SDK.


You can query the event_member FQL table, something like:

FB.api(
    {
        method: 'fql.query',
        query: 'select rsvp_status from event_member where eid = "EVENT_ID" and uid=me()'
    }, function(response) {
        alert(response[0].rsvp_status);
    }
);

Would return (alert) something like: declined


You can use the Graph API to do this. There are two scenarios that may be of interest: (1) For an event, you want to list if the user is attending, and (2) for a user, you want to list the event's they're attending. You need the user_events permission for both scenarios.

For (1): HTTP GET /EVENT_ID/attending. This will return an array of objects with {id, name, rsvp_status} fields. Look for the User ID you're interested in and, if they've RSVP'd, then the rsvp_status field will tell you if they're attending.

For (2): HTTP GET /USER_ID/events. This will return all the events for the user with several fields, but also {id, name, rsvp_status} fields as above. This time, look for the Event ID you're interested in, and then the rsvp_status field will tell you if the current user is attending, not attending, maybe attending, or hasn't RSVP'd (i.e. rsvp_status is unsure).


Actually, there's an easier way to do all of this. The problem with the FQL query is that there's a delay of like 15-30 seconds after you submit the RSVP for the status to show up. But this works in the graph API without pagination. Try a GET request in this form:

/[event id]/invited?user=[user_id]&access_token=[access_token]

It'll return a data structure with the rsvp_status if the user has RSVPed at all, including for public events where that user wasn't technically "invited." If the data structure is blank, then they haven't RSVPed at all.

0

精彩评论

暂无评论...
验证码 换一张
取 消