【问题标题】:How to send app invite to facebook friends on the facebook mobile app?如何在 facebook 移动应用上向 facebook 好友发送应用邀请?
【发布时间】:2012-08-27 12:26:50
【问题描述】:

我有一个网站和一个 Facebook 画布应用程序。网站上的用户可以创建内容,然后邀请他们的 Facebook 朋友查看。当他们这样做时,他们的朋友将在 facebook(在 facebook.com 上)收到通知,并且该链接会将他们带到我的 facebook 画布页面。工作正常。

现在,我想为使用 facebook 移动应用程序(不是 facebook.com)的朋友做同样的事情。因此,如果我网站上的用户邀请朋友,我希望该朋友能够在他们的 facebook 移动应用程序中看到通知,然后单击将他们带到我的网站以查看内容的链接。我的网站没有移动应用程序,因此我希望通过网络浏览器将链接转到我的网站。

这可能吗?

如果没有,让您的网站允许用户邀请 facebook 朋友,然后这些朋友在 facebook 移动应用程序上收到通知的最佳方式是什么?

这很重要的原因是因为我网站上的用户将创建时间敏感的内容,所以我不希望他们必须等待他们的朋友亲自到他们的 facebook.com 上的计算机。我希望他们的朋友在世界任何地方打开 facebook 移动应用程序时都能立即获得它。

【问题讨论】:

    标签: facebook center


    【解决方案1】:

    此代码可帮助您发布、发送消息以及向您的朋友发送请求:

    头部标签:

    <script type="text/javascript">
      function logResponse(response) {
        if (console && console.log) {
          console.log('The response was', response);
        }
      }
    
      $(function(){
        // Set up so we handle click on the buttons
        $('#postToWall').click(function() {
          FB.ui(
            {
              method : 'feed',
              link   : $(this).attr('data-url')
            },
            function (response) {
              // If response is null the user canceled the dialog
              if (response != null) {
                logResponse(response);
              }
            }
          );
        });
    
        $('#sendToFriends').click(function() {
          FB.ui(
            {
              method : 'send',
              link   : $(this).attr('data-url')
            },
            function (response) {
              // If response is null the user canceled the dialog
              if (response != null) {
                logResponse(response);
              }
            }
          );
        });
    
        $('#sendRequest').click(function() {
          FB.ui(
            {
              method  : 'apprequests',
              message : $(this).attr('data-message')
            },
            function (response) {
              // If response is null the user canceled the dialog
              if (response != null) {
                logResponse(response);
              }
            }
          );
        });
      });
    </script>
    

    正文标签:

    <body>
    <div id="fb-root"></div>
    <script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'xxxxxxxxxxxxxxxxxxx', // App ID
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          xfbml      : true // parse XFBML
        });
    
        // Listen to the auth.login which will be called when the user logs in
        // using the Login button
        FB.Event.subscribe('auth.login', function(response) {
          // We want to reload the page now so PHP can read the cookie that the
          // Javascript SDK sat. But we don't want to use
          // window.location.reload() because if this is in a canvas there was a
          // post made to this page and a reload will trigger a message to the
          // user asking if they want to send data again.
          window.location = window.location;
        });
    
        FB.Canvas.setAutoGrow();
      };
    
      // Load the SDK Asynchronously
      (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";
        fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));
    </script>
    
    <header class="clearfix">
      <?php if (isset($basic)) { ?>
      <p id="picture" style="background-image: url(https://graph.facebook.com/<?php echo he($user_id); ?>/picture?type=normal)"></p>
    
      <div>
        <h1>Welcome, <strong><?php echo he(idx($basic, 'name')); ?></strong></h1>
        <p class="tagline">
          This is your app
          <a href="<?php echo he(idx($app_info, 'link'));?>" target="_top"><?php echo he($app_name); ?></a>
        </p>
    
        <div id="share-app">
          <p>Share your app:</p>
          <ul>
            <li>
              <a href="#" class="facebook-button" id="postToWall" data-url="<?php echo AppInfo::getUrl(); ?>">
                <span class="plus">Post to Wall</span>
              </a>
            </li>
            <li>
              <a href="#" class="facebook-button speech-bubble" id="sendToFriends" data-url="<?php echo AppInfo::getUrl(); ?>">
                <span class="speech-bubble">Send Message</span>
              </a>
            </li>
            <li>
              <a href="#" class="facebook-button apprequests" id="sendRequest" data-message="Test this awesome app">
                <span class="apprequests">Send Requests</span>
              </a>
            </li>
          </ul>
        </div>
      </div>
      <?php } else { ?>
      <div>
        <h1>Welcome</h1>
        <div class="fb-login-button" data-scope="user_likes,user_photos"></div>
      </div>
      <?php } ?>
    </header>
    

    【讨论】:

    • 这很棒。我将使用提供的代码进行测试。你知道这种类型的帖子是否会出现在 Facebook 移动应用上用户的 Facebook 订阅源上吗?例如,如果我使用此代码向您发帖,而您在您的 facebook 移动应用上,您会看到该帖子吗?
    【解决方案2】:

    来自 Facebook Mobile Web Tutorial

    function sendRequest() {
      FB.ui({
        method: 'apprequests',
        message: 'invites you to learn how to make your mobile web app social',
      }, 
      function(response) {
        console.log('sendRequest response: ', response);
      });
    }
    

    更多详情,请参阅Request Dialog documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多