开发者

Inviting selected users to Facebook-Event (via Graph API)

开发者 https://www.devze.com 2023-03-25 20:30 出处:网络
with help of docs, tutorials and this forum I managed to create an event for the logged in user on his profile or page, as he chooses.

with help of docs, tutorials and this forum I managed to create an event for the logged in user on his profile or page, as he chooses. I also figured, that for inviting friends I'd have to use events.invite.

Since I don't want to invite all of the user's friends but several, I implemented a request, which as a result returns the selected friend's ids.

Those I'm using for the events.invite call. I get bool 1 as result (which means, the invitation was sent successfully) but there is no invitation to be seen in friends bookmarks or event page.

Everything besides invitation is working.

3 questions come up:

1) Does events.invite need additional permission besides 'create_event' ? I tryed events.invite independently and couldn't get results either...

2) Is there a better way to select friends before sending invitation? I do not want app request being sent out each time an event is created.

3) If 2 is negative, how ca开发者_JAVA技巧n the app request (and bookmark) be subdued or removed from friend's profile? Deleting the request via API obviously doesn't remove the message in application requests.

* in main script: [javascript]

function sendRequest() {
FB.ui({
      method: 'apprequests',
      message: 'Test',
      title: 'event invitation for up to 20 friends',
      max_recipients: 20,
      },
  function (response) {
     if (response && response.request_ids) {
        var requests = response.request_ids.join(',');
        var invite_ids = new Ajax.Request('/facebook/handle_invitation.php', {
             onSuccess: function(test) { alert('Done!'); },
             method: 'post',
             parameters: {tid: '<?php echo $target_id; ?>',
                          request_ids: requests, 
                          eid:'<?php echo $event_id; ?>',
                          token: '<?php echo $access_token; ?>'}
             });
     } else {
         alert('canceled');
     }

  });
        return false;
  }

* and in 'handle_invitation.php' (called from request response):

if( isset($_POST['request_ids']) && isset($_POST['uid']) ) {
  $target_id = $_POST['tid'];
  $event_id = $_POST['eid'];
  $access_token = $_POST['token'];
  $requests = explode(',',$_POST['request_ids']);


foreach($requests as $request_id) {
    $request_data = $fb->api("/$request_id?$access_token");
    $invite_id[] = $request_data['to']['id'];

    $fb->api("/$request_id?$access_token", "DELETE");
    }


//invite friends to my event
$return = $fb->api(array(
   'method' => 'events.invite',
   'eid' => $event_id,
   'uids' => $invite_id,
   'personal_message' =>"Einladung zu meinem Event"
)); 
}

Hope this was not too detailed. I'd appreciate any help, since after days of reading and experimenting I'm finally stuck at this point. Thx!


The graph api now allows you to invite users by user_id. See http://developers.facebook.com/docs/reference/api/event/

invited

Create

You can invite users to an event by issuing an HTTP POST to /EVENT_ID/invited/USER_ID. You can invite multiple users by issuing an HTTP POST to /EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3. Both of these require the create_event permission and return true if the invite is successful.


I don't think "sent event invitation" is in the GRAPH API yet. It is available in REST API but its not working as we expect. I found some known issues and limitations with facebook events. Please see the links below from the official documentation on facebook

Limitation on number of people that could be invited to an event. http://www.facebook.com/help/?faq=12576#!/help/?faq=202545109787461

Event members are not receiving messages I have sent. http://www.facebook.com/help/?page=786#!/help/?faq=188295427885002

0

精彩评论

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

关注公众号