2011-02-12 188 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必须在您的应用程序域中列入白名单。