2012-09-02 50 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

相關問題