Twitter和Facebook分享回调? [英] Twitter and facebook share with callbacks?

查看:461
本文介绍了Twitter和Facebook分享回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的网站上实现了Facebook和Twitter的分享。当用户点击Twitter或Facebook分享按钮时,用户将重定向到以下网址。



http://www.facebook.com/sharer.php?u= '+ encodeURIComponent(location)+'& t ='+ encodeURIComponent(text)



http://twitter.com/share?url = '+ location +'& text ='+ text



如果可能,我想在我的数据库中存储用户名和tweet链接,叽叽t witter witter when when when。。。。。。。。。。。。

解决方案

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/',
图片:'http://fbrell.com/f8.jpg',
caption:'参考文档',
描述:'对话框提供一个简单,一致的界面,用于应用程序与用户接口',
消息:'Facebook对话框很简单!
},
函数(响应){
if(response&& response.post_id){
alert('Post was published。');
} else {
alert('Post was not published。');
}
}
);

要使用此功能,您需要设置一个Facebook应用程序,并在打开后直接放入以下代码body标签

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

如果您要求基本权限,您可以获取用户的Facebook id,并使用它来存储哪些用户共享。


I have implemented facebook and twitter share to my website. The users are redirected to the following URLs when they click on the twitter or facebook share button.

http://www.facebook.com/sharer.php?u='+encodeURIComponent(location)+'&t='+encodeURIComponent(text)

http://twitter.com/share?url='+location+'&text='+text

I want to store the username and tweet link if possible in my database when someone the content through twitter and I want to store facebook profile url and name when someone shares it through facebook. Is it possible to retrive that data when someone has successfully completed the share process?

解决方案

The facebook javascript API allows you to share and gives you a callback

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.');
     }
   }
 );

To use this you need to have set up a facebook application and put the following code directly after the opening body tag

<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>

If you ask for basic permissions, you could then get the users facebook id and use this to store which users had shared.

这篇关于Twitter和Facebook分享回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆