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

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

问题描述

我已经在我的网站上实现了 facebook 和 twitter 共享.当用户点击 twitter 或 facebook 分享按钮时,他们会被重定向到以下 URL.

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

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

如果可能的话,我想在我的数据库中存储用户名和推文链接,当有人通过 twitter 获取内容时,我想在有人通过 facebook 分享时存储 facebook 个人资料 url 和姓名.当有人成功完成共享过程后,是否可以检索该数据?

解决方案

facebook javascript API 允许你分享并给你回调

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

FB.ui({方法:'饲料',name: 'Facebook 对话',链接:'http://developers.facebook.com/docs/reference/dialogs/',图片:'http://fbrell.com/f8.jpg',标题:'参考文档',描述:对话框为应用程序与用户交互提供了一个简单、一致的界面.",消息:Facebook 对话很简单!"},功能(响应){如果(响应&& response.post_id){alert('帖子已发布.');} 别的 {alert('帖子未发布.');}});

要使用它,您需要设置一个 facebook 应用程序并将以下代码直接放在开头的正文标签之后

<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script><script type="text/javascript">FB.init({appId:YOUR_API_KEY,状态:真实,饼干:是的,xfbml: 真});FB.Canvas.setAutoResize();

如果您要求基本权限,则可以获取用户的 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天全站免登陆