Created
December 9, 2010 22:53
-
-
Save jonathan-beebe/735463 to your computer and use it in GitHub Desktop.
Using the Facebook Javascript API you can execute a friend request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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