【问题标题】:Send message to multiple recipients using Facebook API使用 Facebook API 向多个收件人发送消息
【发布时间】:2012-04-14 09:38:41
【问题描述】:

是否有任何其他方式可以将消息发布给多个收件人。 我们试图整合逻辑,这里描述Facebook send dialog to multiple friends using a recipients arrays 但它现在看起来不起作用。它只允许向 ID 列表中的第一个收件人发送信息。

感谢您的帮助。

【问题讨论】:

标签: javascript facebook web dialog send


【解决方案1】:

我找到了一种将 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.com 地址发送消息,但它们总是隐藏在“垃圾邮件”文件夹中。有任何想法吗? webapps.stackexchange.com/questions/44844/…
  • 值得注意的是,此功能不再起作用,发送到 user_id@facebook.com 的电子邮件将被退回。
【解决方案2】:

Facebook 不希望你这样做,所以你必须做一个变通办法……你可以开发一个带有内置消息系统的应用程序。然后同时向多个收件人发送请求。当用户点击请求时,您的应用应检索并显示消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多