使用 JavaScript sdk 邀请朋友加入 Facebook
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6829864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invite friends to Facebook using JavaScript sdk
提问by Eslam Soliman
I am new to stack overflow, how can 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.
我是堆栈溢出的新手,如何使用 javascript SDK 以编程方式邀请我的 Facebook 朋友加入我的 Facebook 应用程序?我是 Facebook-Javascript 的新手。我想使用我的 Facebook 应用程序向用户的朋友发送邀请。
回答by Tom
Here is my code, uses jQuery:
这是我的代码,使用 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;
} ;
回答by Eslam Soliman
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 :
这是代码,消失的功能是从您可以更改它的路径中获取您的 appId 并且不要忘记 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>