2011-02-12 187 views
14

我已將facebook和twitter分享到我的網站。當用戶點擊Twitter或Facebook分享按鈕時,用戶將被重定向到以下URL。Twitter和Facebook分享回調?

http://www.facebook.com/sharer.php?u= '+ encodeURIComponent方法(位置)+' &噸= '+ encodeURIComponent方法(文本)

http://twitter.com/share?url= '+位置+' &文本=' +文本

我想要存儲的用戶名和鳴叫鏈路如果有可能在我的數據庫中,當有人通過Twitter的內容,我想存儲Facebook的個人資料網址和名稱,當有人分享它通過Facebook。當有人成功完成共享過程時,是否可以檢索這些數據?

+0

Twitter並看看 http://stackoverflow.com/questions/4947825/is-there-a-callback-for-twitters-tweet-button – 2012-05-17 19:23:51

回答

0

打開FB共享窗口後,由用戶決定是否發佈內容。沒有回調函數,並且不可能知道他是否已完成該進程。

您可能想要實現FB連接並創建自己的表單,以在填充字段後發佈到用戶的牆上(也可以選擇將其保存在數據庫中)。

我不知道Twitter是否提供了您要求的功能,但我會採用與上述相同的解決方案。

+1

有對tweetbuttons回調的開放特性請求:HTTP ://code.google.com/p/twitter-api/issues/detail?id = 1835 – abraham 2011-02-13 01:47:48

+0

很酷!感謝您的信息;) – 2011-02-13 12:23:58

+2

這可能是一個過時的評論。此頁面上的另一個答案提供了一個有效的回調解決方案,而這個答案聲稱沒有。 – gcdev 2015-05-01 20:16:45

18

了Facebook的JavaScript API,可以讓你分享,給你一個回調

http://developers.facebook.com/docs/reference/javascript/FB.ui/

FB.ui(
    { 
    method: 'feed', 
    name: 'Facebook Dialogs', 
    link: 'http://developers.facebook.com/docs/reference/dialogs/', 
    picture: 'http://fbrell.com/f8.jpg', 
    caption: 'Reference Documentation', 
    description: 'Dialogs provide a simple, consistent interface for applications to interface with users.', 
    message: 'Facebook Dialogs are easy!' 
    }, 
    function(response) { 
    if (response && response.post_id) { 
     alert('Post was published.'); 
    } else { 
     alert('Post was not published.'); 
    } 
    } 
); 

要使用此,你需要建立了一個Facebook應用程序,並在開盤後直接把下面的代碼身體標記

<div id="fb-root"> 
</div> 
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script> 
<script type="text/javascript"> 
    FB.init({ 
     appId: YOUR_API_KEY, 
     status: true, 
     cookie: true, 
     xfbml: true 
    }); 
    FB.Canvas.setAutoResize(); 
</script> 

如果您要求基本的權限,那麼您可以獲取用戶的臉書ID並使用它來存儲哪些使用rs已經分享。

15

Twitter並調用與回調,這就是我在Javascript中做到了:

// Include the Twitter Library 
window.twttr = (function (d,s,id) { 
    var t, js, fjs = d.getElementsByTagName(s)[0]; 
    if (d.getElementById(id)) return; js=d.createElement(s); js.id=id; 
    js.src="https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); 
    return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } }); 
}(document, "script", "twitter-wjs")); 

// On ready, register the callback... 
twttr.ready(function (twttr) { 
    twttr.events.bind('tweet', function (event) { 
     // your callback action here... 
    }); 
}); 

Twitter的鏈接是這樣的:

 <a href="https://twitter.com/intent/tweet?url=URLTOBESHARED">Share on Twitter</a> 

參考:https://dev.twitter.com/docs/intents/events

0

對於Facebook來說,有一個帶回調的更新的共享對話框(來源:https://developers.facebook.com/docs/sharing/reference/share-dialog

https://www.facebook.com/dialog/share? 
app_id=145634995501895 
&display=popup 
&href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2F 
&redirect_uri=https%3A%2F%2Fdevelopers.facebook.com%2Ftools%2Fexplorer 

您必須提供app_id,並且redirect_uri必須在您的應用程序域中列入白名單。