0

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"]);
     }
dana
  • 5,168
  • 20
  • 75
  • 116

1 Answers1

0

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

ifaour
  • 38,035
  • 12
  • 72
  • 79
  • i tried like this and it throws me the error : API Error Code: 191 API Error Description: The specified URL is not owned by the application Error Message: redirect_uri is not owned by the application. though i don't declare any new url in the script above. (and without this scrips i don;t ave any errors. any hints? thanks!) – dana Jan 21 '12 at 05:58
  • @dana have you changed the `appId` in the above example to yours? also what your App Domain is set to in your App settings? – ifaour Jan 21 '12 at 06:05
  • yes, now it works (the dialog) but doesn;t actually send invitations :( . i mean the target user doesn't receive any notifications to use the app – dana Jan 21 '12 at 06:22
  • Also now for page tab applications, you need to specify the display type -> display: 'popup' – MrDustpan Nov 02 '12 at 15:08