how to send a facebook game request in php

sridhar picture sridhar · Feb 24, 2011 · Viewed 9.2k times · Source

OK i know there is tons of documentation out there for using a request form and that is not my question.

I am writing a similar app like many other game apps that need to send "game requests", but i scoured through the documentation only to find that I am bound to using these two ways:

  1. Wall post (dont want to use this since I cannot use privacy settings on messages on friend's wall)
  2. fb:request-form

the request form would suffice if I can somehow pre-populate the friend ids and automatically send it out, but I dont know how to do that. Can anyone help?

But how does Farmville and others do this? They send requests of type "game requests".

Gotta get me some information - help!!

Answer

MetaLik picture MetaLik · Apr 11, 2011

You can send Request with Facebook Request Dialog. Try have a look with the following link:

http://developers.facebook.com/docs/reference/dialogs/requests/

Some code snippet from my App:

   function inviteFriends() {
        FB.ui(
            {
                method: 'apprequests', 
                title: 'Invite your friend to our cool facebook app', 
                message: 'Please join our cool facebook app',
                data: {requestType:"myRequestType", someOtherInfo:"blahblahblah"}
            },
            function(response) {
                if (response) {
                    // Can save the request id if needed
                    alert('Request ID: '+response.request_ids);
                } else {
                    alert('Post was not published.');
                }
            }
        );
    }

When the target user has "Accepted" your request, Facebook will redirect user to your App's with the request_ids as parameters. You can further process your request with the request IDs