使用Facebook API向多个收件人发送消息
是否有任何其他方式将消息发布到多个收件人。 我们尝试过整合逻辑,在这里描述Facebook send dialog to multiple friends using a recipients arrays ,但现在看起来不行。它只允许在ID列表中向第一个收件人发送信息。使用Facebook API向多个收件人发送消息
感谢您的帮助。
Facebook不希望你这样做,所以你必须做一个解决方法...你可以开发一个内置消息系统的应用程序。然后同时向多个收件人发送请求。当用户点击该请求时,您的应用程序应该检索并显示该消息。
我发现了一个将Facebook消息发送给多个朋友的解决方法。
每个Facebook用户都会自动获得@ facebook.com电子邮件地址。 该地址与公共用户名或公共用户标识相同。
所以你可以简单地发送一个普通的电子邮件到这个电子邮件地址。 邮件将像正常消息一样显示在Facebook收件箱中。
重要的是您使用连接的用户电子邮件作为发件人,否则它将无法正常工作。
下面是一个例子,它获取所有朋友的电子邮件地址并调用Web服务。
<div id="fb-root"></div>
<script type="text/javascript" src="https://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
FB.init({
appId: '#APP_ID#',
status: true,
cookie: true,
xfbml: true
});
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
GetData();
} else {
Login();
}
});
function Login() {
FB.login(function (response) {
if (response.authResponse) {
GetData();
}
}, { scope: 'email' });
}
function GetData() {
//Get user data
FB.api('/me', function (response) {
//Sender
var sender = response.email;
//Get friends
FB.api('/me/friends', function (response) {
//Recepients array
var recipients = [];
var length = response.data.length;
var counter = 0;
//Loop through friends
for (i = 0; i < length; i++) {
var id = response.data[i].id;
//Get friend data
FB.api('/' + id, function (response) {
var recipient = "";
//User got a username, take username
if (response.username) {
recipient = response.username + '@facebook.com';
}
//No username, take id
else {
recipient = response.id + '@facebook.com';
}
//Add e-mail address to array
recipients.push(recipient);
counter++;
//last email -> send
if (counter == length) {
SendEmail(sender, recipients);
}
});
}
});
});
}
function SendEmail(sender, recipients) {
//Call webservice to send e-mail e.g.
$.ajax({ type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
url: '#WEBSERVICE#',
data: '{ sender:"' + sender + '", recipients: ["' + recipients.join('","') + '"] }',
success: function (response) {
//do something
}
});
}
</script>
我试图发送消息到@ facebook.com地址,但他们总是隐藏在“垃圾邮件”文件夹中。有任何想法吗? http://webapps.stackexchange.com/questions/44844/why-does-email-sent-to-my-facebook-com-address-always-end-up-in-facebook-messag – 2013-05-29 16:58:41
值得注意的是,此功能不会不再工作了,发送给[email protected]的电子邮件将会反弹。 – 2017-01-12 10:17:42
看到这个答案,解决方案似乎使用与Facebook用户ID的数组http://stackoverflow.com/questions/6469748/facebook-send-dialog-to-multiple-friends-using-a-recipients - 阵列 – 2013-07-05 15:26:40