Search code examples
facebookfacebook-appsfacebook-recommendations

Facebook application requests


i am trying to implement a facebook request in a page tab application. i have seen the tutorial here http://developers.facebook.com/docs/appsonfacebook/tutorial/ but the problem is that i want the code below to be executed only when someone accesses a link like

<a href = "something">Send to friends</a>

any idea about how can this be done? thanks!

   $requests_url = "http://www.facebook.com/dialog/apprequests?app_id=" 
            . $app_id . "&redirect_uri=" . urlencode($the_url_of_the_tab_page)
            . "&message=" . $message;

     if (empty($_REQUEST["request_ids"])) {
        echo("<script> top.location.href='" . $requests_url . "'</script>");
     } else {
        echo "Request Ids: ";
        print_r($_REQUEST["request_ids"]);
     }

Solution

  • The request dialog is what you are looking for:

    <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:fb="https://www.facebook.com/2008/fbml">
      <head>
        <title>Request Tester C</title>
      </head>
    
      <body>
        <div id="fb-root"></div>
        <script src="http://connect.facebook.net/en_US/all.js"></script>
        <p>
          <input type="button"
            onclick="sendRequestToRecipients(); return false;"
            value="Send Request to Users Directly"
          />
          <input type="text" value="User ID" name="user_ids" />
          </p>
        <p>
        <input type="button"
          onclick="sendRequestViaMultiFriendSelector(); return false;"
          value="Send Request to Many Users with MFS"
        />
        </p>
    
        <script>
          FB.init({
            appId  : 'YOUR_APP_ID',
            status : true,
            cookie : true,
            oauth: true
          });
    
          function sendRequestToRecipients() {
            var user_ids = document.getElementsByName("user_ids")[0].value;
            FB.ui({method: 'apprequests',
              message: 'My Great Request',
              to: user_ids, 
            }, requestCallback);
          }
    
          function sendRequestViaMultiFriendSelector() {
            FB.ui({method: 'apprequests',
              message: 'My Great Request'
            }, requestCallback);
          }
    
          function requestCallback(response) {
            // Handle callback here
          }
        </script>
      </body>
    </html>
    

    So your "link" shouldn't be calling a real url but instead a Javascript function to open the Request Dialog (in the above example it'll be sendRequestViaMultiFriendSelector()).