我已将facebook和twitter分享到我的网站.用户在点击推特或Facebook分享按钮时会被重定向到以下网址.
http://www.facebook.com/sharer.php?u='+ encodeURIComponent(location)+'&t ='+ encodeURIComponent(text)
http://twitter.com/share?url='+ location +'&text ='+ text
如果可能的话,我希望在我的数据库中存储用户名和推文链接,当有人通过推特内容时,我想存储facebook个人资料网址和名称,当有人通过Facebook分享时.有人成功完成共享过程后,是否可以检索该数据?
Tom*_*Tom 19
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.');
}
}
);
Run Code Online (Sandbox Code Playgroud)
要使用此功能,您需要设置一个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>
Run Code Online (Sandbox Code Playgroud)
如果您要求基本权限,则可以获取用户的facebook id并使用它来存储共享的用户.
小智 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...
});
});
Run Code Online (Sandbox Code Playgroud)
twitter链接是这样的:
<a href="https://twitter.com/intent/tweet?url=URLTOBESHARED">Share on Twitter</a>
Run Code Online (Sandbox Code Playgroud)
参考:https://dev.twitter.com/docs/intents/events
一旦打开FB分享窗口,是否发布内容由用户决定。没有回调函数,无法知道他是否完成了该过程。
您可能想要实现 FB 连接并创建自己的表单,以便在用户填写字段后将其发布到用户墙上(并且您也可以选择将它们保存在数据库中)。
我不知道 Twitter 是否提供您所请求的功能,但我会采用与上述相同的解决方案。