2012-09-02 61 views
0

我有一个网站和一个脸书画布应用程序。网站上的用户可以创建内容,然后邀请他们的Facebook好友看到它。当他们这样做时,他们的朋友会在脸书(facebook.com)上收到通知,链接将把他们带到我的脸书画布页面。工作正常。如何在facebook移动应用程序上向Facebook上的朋友发送应用程序邀请?

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

这可能吗?

如果不是,最好的办法是让您的网站允许用户邀请Facebook好友,然后这些朋友在facebook手机应用程序上获得通知?

之所以这很重要,是因为我网站上的用户会创建时间敏感的内容,所以我不希望他们不得不等待他们的朋友在facebook.com上实际在他们的计算机上。我希望他们的朋友在他们在世界任何地方打开Facebook移动应用程序时马上得到它。

回答

1

此代码可以帮助你张贴,发送邮件,并发送请求给您的朋友:

head标签:

<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> 
+0

这太好了。我将使用提供的代码进行测试。你知道这种类型的文章是否会显示在Facebook移动应用的用户Facebook上?例如,如果我使用此代码发布给您,并且您位于您的Facebook移动应用程序中,您会看到该帖子吗? – Stoop

0

从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

相关问题