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

試著忘記壹切 提交于 2019-12-01 09:03:23

问题


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 this using the JS SDK.


回答1:


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




回答2:


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).




回答3:


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.



来源:https://stackoverflow.com/questions/7312964/checking-for-event-rsvp-status-and-showing-disabled-enabled-rsvp-button

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