Search code examples
c#asp.netfacebookinvite

Inviting users to a pre-existing facebook event using the REST API


What is the best way to invite users to an existing event? We'd like to do the following:

  • create an event, make it public
  • while on our (external) website give the user a dialog (fb:multi-friend-selector) to select their friends to invite to the event

It's established the new Graph API can't be used (http://bugs.developers.facebook.net/show_bug.cgi?id=10070), but the documentation for the REST API (http://developers.facebook.com/docs/reference/rest/events.invite) implies that it's not possible to invite users to existing events.

If anyone could provide any clarity on this I'd be grateful - reading the vague and contradictory facebook documentation is getting me nowhere.

Specifically, who/where/how should the event be created? - and how can I then invite users to that event from an external website?


Solution

  • This can be done using the Graph API. To use the JavaScript SDK use the following:

    FB.api('/[EVENT-ID-HERE]/attending', 'post');
    

    This can only be done once you have an authenticated user, so in full, the code would be:

    <div id="fb-root"></div>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
    FB.init({
        appId: '[APP-ID-HERE]', cookie: true, status: true, xfbml: true
    });
    FB.Event.subscribe('auth.login', function (response) {
        if (response.session) {
            FB.api('/[EVENT-ID-HERE]/attending', 'post');
        }
    });
    </script>       
    <fb:login-button perms="rsvp_event">Attend Event</fb:login-button>