推特的“关注按钮"是否有回调选项?小部件 [英] is there a callback option with twitter's "follow button" widget

查看:46
本文介绍了推特的“关注按钮"是否有回调选项?小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 this 在我的 twitter 网站上创建 twitter 关注按钮-应用程序.实现就这么简单:

I'm using this for creating twitter follow buttons on my twitter web-app. Implementation is as easy as this:

<span id="follow-twitterapi"></span>
<script type="text/javascript">

  twttr.anywhere(function (T) {
    T('#follow-twitterapi').followButton("twitterapi");
  });

</script>

当您将该代码放入 html 文档时,您会在 iframe 的 span 元素中获得此按钮:

when you put that code into your html document you get this button in that span element in an iframe:

点击关注后,你会得到这个(或类似的话,说你在关注@someone):

after you click follow, you get this (or a similar thing saying you're following @someone):

但是,在使用此按钮后,我无法将任何信息返回到我的应用程序,(因为这是在 iframe 中呈现的,并且由于 javascript 的同源策略,我无法访问该 iframe 的内容),此小部件是否提供了任何方法,以在用户开始关注某人时通知我的应用使用此小部件?

however i can't get any information back to my app after this button is used, (because this is rendered in an iframe and because of same-origin policy of javascript, i can't access to contents of that iframe), is there any methods provided with this widget, to inform my app when a user starts following someone using this?

谢谢.

推荐答案

可以.这是我的代码:

<a href="https://twitter.com/gafitescu" class="twitter-follow-button">Follow @gafitescu</a>    
 <script src="//platform.twitter.com/widgets.js" type="text/javascript"></script>
<script type="text/javascript">
    twttr.events.bind('follow', function(event) {
        console.log(event);
        var followed_user_id = event.data.user_id;
        var followed_screen_name = event.data.screen_name;
    });
</script>

这篇关于推特的“关注按钮"是否有回调选项?小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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