使用 Facebook Javascript API 发送消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16096101/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 03:15:03  来源:igfitidea点击:

Send message with Facebook Javascript API

javascriptfacebook

提问by quarks

I have already included this in my page html:

我已经将它包含在我的页面 html 中:

<div id="fb-root"></div>
<script type="text/javascript" language="javascript">
    (function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</script>

And that I have facebook-like boxin my page already, however I need to do now a way to send messages to email using the Facebook Javascript API. Is this configuration enough to call a "send message"?

并且我已经facebook-like box在我的页面中,但是我现在需要做一种使用 Facebook Javascript API 将消息发送到电子邮件的方法。这个配置是否足以调用“发送消息”?

I have a custom HTML form in which when I click send I like it to send a message on my Facebook page's behalf. I have my page up in Facebook.

我有一个自定义 HTML 表单,当我点击发送时,我喜欢它代表我的 Facebook 页面发送消息。我在 Facebook 上有我的页面。

  • I need to send message without any server side component (pure Javascript)
  • I have a existing Facebook page (which I will use to send messages with)
  • I have a custom form in which will be used to type in message.
  • The message will be sent to some specific email address
  • I can send to any email with Facebook so I assume this will work
  • 我需要发送没有任何服务器端组件的消息(纯 Javascript)
  • 我有一个现有的 Facebook 页面(我将用它来发送消息)
  • 我有一个自定义表单,用于输入消息。
  • 该消息将发送到某个特定的电子邮件地址
  • 我可以用 Facebook 发送到任何电子邮件,所以我认为这会奏效

采纳答案by luschn

I will answer your questions separately:

我将分别回答您的问题:

  • I need to send message without any server side component (pure Javascript)
  • 我需要发送没有任何服务器端组件的消息(纯 Javascript)

If it can be a simple message to a facebook user, you have to use the FB.ui send dialog: https://developers.facebook.com/docs/reference/dialogs/send/That′s pretty much the only way for you, you can just try putting in an email address in the popup. According to the documentation, it should work.

如果它可以是给 facebook 用户的简单消息,则您必须使用 FB.ui 发送对话框:https: //developers.facebook.com/docs/reference/dialogs/send/这几乎是唯一的方法你,你可以尝试在弹出窗口中输入一个电子邮件地址。根据文档,它应该可以工作。

  • I have a custom form in which will be used to type in message.
  • 我有一个自定义表单,用于输入消息。

That′s where even the send dialog will not work anymore. You cannot prefill the message parameter, what you want would only be possible with the PHP SDK of Facebook. But then again: Why would you program the textfield on your own, if Facebook already offers everything in that dialog?

这就是即使发送对话框也不再起作用的地方。您不能预填充 message 参数,您想要的只有 Facebook 的 PHP SDK 才能实现。但话又说回来:如果 Facebook 已经在该对话框中提供了所有内容,您为什么要自己编写文本字段?

Without that dialog, there is no way to just send a message in the background without a server side language like PHP.

没有那个对话框,就没有办法在没有像 PHP 这样的服务器端语言的情况下在后台发送消息。

回答by Rishabh

Adding to the above answers. You might want to make a function.

补充上面的答案。您可能想要创建一个函数。

<div class="facebook-invite">
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <div id="fb-root">
        <a href="#" onclick="FBInvite()">Invite Facebook Friends</a>
    </div>
    <script>

      FB.init({appId: 'XXXXXXXX', xfbml: true, cookie: true});
        function FBInvite(){

      FB.ui({
          method: 'send',
          name: 'Join This website it is cool',
          link: 'rishabhjainiitbhu.ac.in',
          });
         }
     </script>
</div>

This will make a link, clickin on which the dialog box will pop up.

这将创建一个链接,单击该链接将弹出对话框。

回答by Lian

Use this: here is the source Facebook send message

使用这个:这是Facebook 发送消息的来源

<html xmlns:fb="https://www.facebook.com/2008/fbml">
  <body>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <div id="fb-root"></div>
    <script>
      // assume we are already logged in
      FB.init({appId: '123050457758183', xfbml: true, cookie: true});

      FB.ui({
          method: 'send',
          name: 'People Argue Just to Win',
          link: 'http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html',
          });
     </script>
  </body>
</html>