使用Facebook API向多个收件人发送消息

Send message to multiple recipients using Facebook API

本文关键字:收件人 消息 Facebook API 使用      更新时间:2023-09-26

是否有其他方式将消息发送给多个收件人。我们已经尝试集成逻辑,在这里描述了Facebook使用收件人数组向多个朋友发送对话框但现在看起来不管用了。它只允许将信息发送给ID列表中的第一个收件人。

谢谢你的帮助。

我找到了一个向多个朋友发送Facebook消息的解决方法

每个Facebook用户都会自动获得一个@Facebook.com电子邮件地址。地址与公共用户名或公共用户ID相同。

因此,您可以简单地向这些电子邮件地址发送常规电子邮件。邮件将像普通邮件一样显示在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不希望你这样做,所以你必须解决。。。你可以开发一个内置消息系统的应用程序。然后同时向多个收件人发送请求。当用户点击请求时,你的应用程序应该检索并显示消息。