2012-06-02 41 views
0

我是Facebook頁面的管理員,並且想要向訪問我的域時喜歡我的頁面的用戶顯示一條消息。僅當用戶喜歡某個頁面時在網站上顯示內容

我可以找到一些關於如何做它作爲頁面選項卡的教程,但我想在我的網站上顯示它。 我怎樣才能使這個工作?我掃描了https://developers.facebook.com/docs/guides/web/但我不知道從哪裏開始?

我做了一個應用程序,並有一個應用ID和應用程序的祕密....但後來......

任何人都可以點我的好的方向發展?


謝謝你的答案,但我猜我不清楚我想要什麼。我不需要的是:在類似按鈕上註冊點擊的方法。

我想要的是以下內容: 用戶喜歡我的Facebook頁面,然後訪問我的網站。在我的網站上,我想向用戶顯示一條消息,例如:「您在Facebook上喜歡我們!做得好」未來我們希望向用戶展示免費啤酒或其他物品的優惠券代碼。

對不起,誤會!

回答

0

我假設你使用JavaScript,因爲你寫了「當他們訪問我的域名。」 挖我從我的舊項目的一個驗證碼了起來:

// load fb 
// don't load if already loaded 
var js, id = 'facebook-jssdk'; 
if(document.getElementById(id)){ 
    return; 
} 

js = document.createElement('script'); 
js.id = id; 
js.async = true; 
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; 
document.getElementsByTagName('head')[0].appendChild(js); 

// when fb has loaded, initialize and add some listeners 
window.fbAsyncInit = function() { 
    FB.init({appId: null, status: true, cookie:true, xfbml:true, trace:true}); 
    FB.Event.subscribe('edge.create', function(h, widget) { 
     // h = liked link 
      // do something eg show message or save state via js cookie or ajax php call 
    }); 
    FB.Event.subscribe('edge.remove', function(h, widget) { 
     // h = unliked link 
      // do something ag hide message or save state via js cookie or ajax php call 
    }); 
}; 

這實際上是Facebook的API的javascript腳本加載的修改。

+0

好但我可以在哪裏指出應該從哪個頁面獲取類似狀態? – stUrb

+0

嗯..我不太明白你在找什麼。 document.location是用戶瀏覽器所在的位置,您可以將它與if語句中的所需內容進行比較,或者您可以在我發佈的代碼中看到,「h」變量包含href,「類似」的「目標」 。 – 19greg96

+0

你誤會了我。請看看我編輯的OP – stUrb

0

您需要創建一個事件偵聽器。它基本上是「手錶」之類按鈕和「告密者」,當有人點擊

添加這個地方在文檔的頭部

<div id="fb-root"></div> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
    FB.init({ apiKey: 'xxxxxxxxxxxxx' }); 

}); 
</script> 

現在我們添加飛賊

window.fbAsyncInit = function() { 
FB.Event.subscribe('edge.create', function(href, widget) { 
alert('You just liked the stUrbs URL '+href); 


}); 
//Add the comment snitch here if you need it. Shown below 
}; 

你當有人發表評論時,可以進一步並進行宣傳:

FB.Event.subscribe('comment.create', function(href, widget) { 
alert('You just commented on stUrbs URL '+href); 


}); 

當然,你會t做比警報更優雅的東西

相關問題