Skip to content

Instantly share code, notes, and snippets.

@jonathan-beebe
Created December 9, 2010 22:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathan-beebe/735463 to your computer and use it in GitHub Desktop.
Save jonathan-beebe/735463 to your computer and use it in GitHub Desktop.
Using the Facebook Javascript API you can execute a friend request
FB.ui(
{
method: 'friends.add',
id: fbid // assuming you set this variable previously...
},
function(param){
console.log(param);
// If they cancel params will show:
// {action:false, ...}
// and if they send the friend request it'll have:
// {action:true, ...}
// and if they closed the pop-up window then:
// param is undefined
}
);
/*
The callback script can then simply performs an ajax call to your server where
you save info about the action, if needed.
You can test this by using the javascript console app on Facebook:
http://developers.facebook.com/tools/console
Paste in the script above, including the <script> tags, or click the "Examples"
button on the bottom of the text area and find the "fb.ui — friends.add" example.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment