简体   繁体   English

发送消息 Facebook Javascript API

[英]Send message with Facebook Javascript API

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 box in 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 向 email 发送消息。此配置是否足以调用“发送消息”?

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.我有一个自定义的 HTML 表单,当我点击发送时,我喜欢它代表我的 Facebook 页面发送消息。 I have my page up in Facebook.我的页面在 Facebook。

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

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. 如果它只是向Facebook用户发送的简单消息,则必须使用FB.ui发送对话框: https : //developers.facebook.com/docs/reference/dialogs/send/这几乎是唯一的方法您,您可以尝试在弹出窗口中输入电子邮件地址。 According to the documentation, it should work. 根据文档,它应该可以工作。

  • 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. 您不能预填充message参数,而只有Facebook的PHP SDK才可以实现。 But then again: Why would you program the textfield on your own, if Facebook already offers everything in that dialog? 但是再说一遍:如果Facebook已经在对话框中提供了所有内容,为什么还要自己编写文本字段?

Without that dialog, there is no way to just send a message in the background without a server side language like PHP. 没有该对话框,就无法在没有像PHP这样的服务器端语言的情况下仅在后台发送消息。

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>

Adding to the above answers.添加到上述答案。 You might want to make a function.你可能想制作一个 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.这将创建一个链接,单击该链接将弹出对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM