I am new to stack overflow, how can 开发者_JAVA百科I invite my Facebook friends to my Facebook application pro-grammatically using javascript SDK? I am a newbie regarding Facebook-Javascript. I want to send an invitation to a user's friends using my Facebook application.
Here is my code, uses jQuery:
$('#popInvite').live('click', sendRequest);
function sendRequest() {
FB.ui({
method: 'apprequests',
message: 'Become my Buddie',
filters: ['app_non_users'],
title: 'Become my Buddie'
},
function (response) {
if (response && response.request_ids) {
//if sucess do something
//How many people did the user invited?
var $howManyInvites = String(requests).split(',').length;
} else {
// alert('canceled');
return false;
}
});
return false;
} ;
here is the code and gone function is to get your appId from the path you can change it and do not forget the fbroot div :
invite
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript">
</script>
<script type="text/javascript">
FB.init({
appId: gone(), cookie: true,
status: true, xfbml: true
});
function shareWithFacebook() {
FB.ui({ method: 'apprequests',
message: 'Here is a new Requests dialog...'
});
}
function gone() {
var pathname = window.location.pathname;
var appId = pathname.split('/')[1];
return appId;
}
</script>
精彩评论