簡體   English   中英

在 Facebook 中集成獨立的 php 應用程序

[英]Integrating standalone php application in Facebook

我創建了一個小應用程序,基本上是一個測驗應用程序(我即將在免費的 web 托管網站上啟動它)。 我想將它與 Facebook 集成。 但主要有2個問題。

  1. 我希望該應用程序僅供我創建的特定組(它是一個封閉組)成員的 FB 用戶使用。

  2. 測驗結束后,應將最終分數張貼在小組牆上。

PS:我的意思是集成,他們只能在使用 Facebook 注冊時開始測試。 歡迎任何其他想法。

您需要對 facebook 做的所有事情(包括但不限於您解釋的確切要求)都可以使用 Facebook Connect API 來實現。 它非常全面,我無法解釋您將如何在此答案中完成整個操作。 這是一個很好的起點:

http://developers.facebook.com/docs/reference/api/

您需要做很多事情。 假設您使用的是 FB JS SDK,您需要使用以下...

  • 通過 FB.login 請求 publish_stream 和 user_groups 擴展權限
  • 通過 FB.api 發布到群牆,例如... FB.api('/GROUP_ID/feed', 'post', { message: 'yay someone done the quiz' }, function(response) { alert(response) ; });

使用 FB JS SDK 的部分示例(未實現組檢查)...

<a onclick="postToGroupWall()">Post msg to group wall</a>

<script>

window.fbAsyncInit = function()
{
    FB.init({
        appId  : 'APP_ID',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true , // parse XFBML
        oauth : true // Enable oauth authentication
    });  

    FB.login(function(response)
    {
        if (response.authResponse)
        {
            alert('Logged in!');

            // Check if user is in group using opengraph call (/me/groups) via FB.api

            // Do that here...
        }
        else
        {
            alert('Not logged in - do something');
        }
    }, { scope : 'publish_stream,user_groups' });
};

window.postToGroupWall = function()
{   
    var opts = {
        message : 'Yay I just completed the quiz',
        name : '',
        link : 'http://www....',
        description : 'Description here',
        picture : 'http://domain.com/pic.jpg'
    };

    FB.api('/GROUP_ID/feed', 'post', opts, function(response)
    {
        if (!response || response.error)
        {
            alert('Posting error occured');
        }
        else
        {
            alert('Success - Post ID: ' + response.id);
        }
    });
};

</script>

<!-- FACEBOOK -->        
<div id="fb-root"></div>
<script>
(function() {
  var e = document.createElement('script');
  // replacing with an older version until FB fixes the cancel-login bug
  e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
  //e.src = 'scripts/all.js';
  e.async = true;
  document.getElementById('fb-root').appendChild(e);
  }());
</script>
<!-- END-OF-FACEBOOK -->

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM