Facebook New javascript SDK friend request

we can send single or multi-friend request through the new javascript sdk .
first we need to add javasript sdk . using this

 <div id="fb-root"></div>
 <script src="http://connect.facebook.net/en_US/all.js"></script>

after that one friend request we can do this

<p>
      <input type="button"
        onclick="sendRequestToRecipients(); return false;"
        value="Send Request to Users Directly"
      />
      <input type="text" value="User ID" name="user_ids" />
       //here user id is whom we send request
      </p>

// here User id is the used id to whom we send request

or if we want to send request through multi friend selector we need this

<p>
    <input type="button"
      onclick="sendRequestViaMultiFriendSelector(); return false;"
      value="Send Request to Many Users with MFS"
    />
    </p>

here is the javascript part

FB.init({
appId : 'YOUR_APP_ID',
status : true,
cookie : true,
oauth: true
});</code>

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
}

if we need to filter our friend list we have to add a line in the function

function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'Invitation request from FBMathGame',
// filters:['app_users'] //for who use this apps
filters:['app_non_users'] //for are not using this apps
//if we use all or remove filters it will show all friends</code>

}, requestCallback);
}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.