2013-09-24 65 views
0

首先對於我的nooby問題抱歉,我幾乎到處檢查,但我沒有正確的答案。有很多文件和教程,但在發展中變化。但是,我的問題是,我有一個粉絲頁面,其中有一個與我的應用程序集成的Tab。Facebook的按鈕不起作用

我只想檢查會話用戶在這裏,他們已經喜歡前或如果他們已經喜歡我的網頁我想更新會話,並得到新的訪問令牌然後將其重定向到我流體畫布頁面(這是我的第二個問題btw。因爲登陸頁面在810px頁面之後,他們喜歡頁面刷新thmeself和它的固定區域再次開放。)

我必須把FB.login按鈕放到我的登陸頁面,還是在應用頁面加載時詢問用戶權限會更好。

我的文件夾模式是這樣的:

-appfolder 
--tab - (landing page in fixed page) 
--app - (app page in fluid canvas) 
--css 
--img 
--js 
--php-sdk 
--index.php (check everything here and redirect in here with login attributes) 
--config.php 
--fbaccess.php 
--fbin.php 
--fbout.php 

着陸頁代碼:

<?php 
    require 'php-sdk/facebook.php'; 

    $app_id = 'xxx'; 
    $app_secret = 'xxx'; 
    // Set 
    $app_namespace = 'hangisienmeshur'; 
    $app_url = 'https://apps.facebook.com/' . $app_namespace . '/'; 
    $scope = 'email,publish_actions'; 

    // Init the Facebook SDK 
    $facebook = new Facebook(array( 
     'appId' => $app_id, 
     'secret' => $app_secret, 
    )); 

    // Get the current user 
    $user = $facebook->getUser(); 
?> 

    <!DOCTYPE html> 
    <html xmlns:fb="http://ogp.me/ns/fb#" xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Tropicana Main</title> 
    <link href="css/normalize.css" rel="stylesheet" type="text/css" /> 
    <link href="css/main.css" rel="stylesheet" type="text/css" /> 
    </head> 

    <body> 

    <div id="fb-root"></div> 

    <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script> 
    <script> 

     window.fbAsyncInit = function() { 
     FB.init({ 
      appId  : 'xxx', // App ID 
      channelUrl : 'http://www.xxx.com/app/xx/channel.php', // Channel File 
      status  : true, // check login status 
      cookie  : true, // enable cookies to allow the server to access the session 
      xfbml  : true // parse XFBML 
     }); 

     // Additional initialization code here 
     FB.Event.subscribe('edge.create', 
      function(response) { 
       window.location.href = 'https://apps.facebook.com/xxx/'; 
      } 
     ); 
     }; 

     // Load the SDK Asynchronously 
     (function(d){ 
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
     if (d.getElementById(id)) {return;} 
     js = d.createElement('script'); js.id = id; js.async = true; 
     js.src = "//connect.facebook.net/en_US/all.js"; 
     ref.parentNode.insertBefore(js, ref); 
     }(document)); 


    </script> 



    <div id="mainfoto"> 
    <div id="fb_button" class="myClass rtl"> 

    <fb:like href="http://www.facebook.com/xxx" width="100" layout="button_count" show_faces="false" send="false"></fb:like> 

</div> 
</div> 

</body> 
</html> 

回答

0

儘量避免在一個Facebook應用程序使用的會話。 Facebook將您的網頁加載到iframe中,由於安全限制,某些瀏覽器(特別是Safari)無法正常使用。

Facebook建議等待,直到他們成爲必要的權限。您可以請求畫布加載權限。最好的用例是等待用戶執行一個需要他們信息的操作(例如,點擊「註冊」按鈕)。

對於你的工作流程,我會建議這種方法。

在登陸頁面上,使用signed request來判斷用戶是否喜歡你的頁面。

$signed = parse_signed_request($_REQUEST['signed_request'], 'YOUR-APP-SECRET'); 
if ($signed['page']['liked'] == 1) { 
    $fan = true; 
} else { 
    $fan = false; 
} 

if ($fan) 
{ 
    echo "window.location.href = 'https://apps.facebook.com/xxx/';"; 
} 
else 
{ 
    echo "<p>Please like the page.</p>"; 
} 

source

這將重定向誰也喜歡你的頁面,到畫布頁面的用戶。沒有的用戶會看到「請喜歡頁面」的消息。

您不需要訂閱'edge.create',因爲點擊「Like」按鈕,會強制頁面重新加載,然後您的代碼會重新定向,因爲用戶現在喜歡該頁面。

+0

感謝您的回覆。我會嘗試一下,我會寫下結果。 –

+0

感謝您的迴應,但它不工作,因爲有APP_ID和其他控制器在這裏失蹤。我不能用這個函數解析我的數據。不工作。 –