2010-01-16 68 views
2

我有一個Facebook應用程序,可以作爲一個選項卡添加到粉絲頁面。該應用程序要求用戶進行身份驗證才能使用它。這可以通過在只有未添加應用程序的用戶才能看到的鏈接中使用requirelogin = 1來完成。這部分工作正常。Facebook的應用程序選項卡網址

但是,在用戶已經從dhtml彈出的requirelogin打開的應用程序權限後,我想要重新加載選項卡。爲了做到這一點,我需要的完整URL被包含在鏈接如下:

<a href="http://www.facebook.com/pages/PAGE_NAME/PAGE_ID?v=app_APP_ID" requirelogin=1>Authorize</a> 

我無法弄清楚如何獲得完整的URL,或者至少,在PAGE_NAME動態構建這個網址。似乎應用程序應該能夠知道它在哪裏,沒有任何特殊的權限。

回答

2

如果您有頁ID和APP ID,這是你做了什麼:

http://www.facebook.com/profile.php?id=PAGE_ID#v=app_APP_ID 

例如:

http://www.facebook.com/profile.php?id=282955631557#v=app_278523304881 
+0

...是的,但這需要提前頁面id(硬編碼)...它不是一個動態的解決方案。 – Paul 2010-04-12 10:25:13

3

當你的標籤加載,API傳遞你Signed Request那除了別的以外,包含page陣列包含id,liked & admin。您可以使用它來動態拉取當前正在調用您的代碼的頁面標識。

+0

page_id **不是**標籤ID,因此您只能重新加載到頁面流,並且如果您在此過程中更改地址,它本身不會重新加載; P – meeDamian 2012-05-08 10:07:35

+0

查看Tytus提供的URL格式 - 應用程序id是靜態的,並且頁面id可以從signed_request中提取。只需糾正他的鏈接中的錯字(而不是#)。即http://www.facebook.com/profile.php?id=PAGE_ID&v=app_APP_ID – 1in9ui5t 2013-09-18 03:29:29

0

在新計劃中,#no long works。人們需要使用

http://www.facebook.com/profile.php?id=PAGE_ID#v=app_APP_ID 

要進行參數的應用程序,它必須是在一個名爲「app_data文件」

http://www.facebook.com/profile.php?id=PAGE_ID#v=app_APP_ID&app_data="..." 

攜帶多個參數的參數,最好的策略就是以JSON編碼app_data文件。

0

以上所有答案都不起作用(僅重定向到頁面流)或現在不推薦使用。你正在使用JS最好的解決辦法:

// called when like button, box, etc is rendered 
FB.Event.subscribe("xfbml.render", function() { 

    // assigns click to that thing 
    FB.Event.subscribe("edge.create", function(response) { 

     window.location.reload(); // reload frame only 

    }); 
}); 

您還可以加載和初始化Facebook的JS SDK。如果你不知道如何去做,使用這個:

<script> 
    document.onload = function(){ 

     (function(d){ 
      var js,id='facebook-jssdk'; 
      if(d.getElementById(id)){return;} 
      js=d.createElement('script'); 
      js.id=id;js.async=true;js.src="//connect.facebook.net/pl_PL/all.js"; 
      d.getElementsByTagName('head')[0].appendChild(js); 
     }(document)); 

     window.fbAsyncInit = function(){ 
      FB.init({ 
       appId : <PASTE_YOUR_APP_ID_HERE>, 
       status : true, // check login status 
       cookie : true, // enable cookies to allow the server to access the session 
       xfbml : true // parse XFBML 
      }); 
      FB.Event.subscribe("xfbml.render", function() { 
       FB.Event.subscribe("edge.create", function(response) { 
        window.location.reload(); 
       }); 
      }); 
     } 
    } 
</script> 
相關問題