New widgets.js

1,039 views
Skip to first unread message

Andrew

unread,
Jun 6, 2011, 8:03:54 AM6/6/11
to Twitter Development Talk
It seems that the widgets.js has been updated and I can no longer load
tweet buttons dynamically with:

var tweet_button = new twttr.TweetButton(<element>);
tweet_button.render();

Does anyone know what the new syntax is?


- Andrew

Tim Meadowcroft

unread,
Jun 6, 2011, 12:09:56 PM6/6/11
to twitter-deve...@googlegroups.com

I believe you're now supposed to do this without an explicit javascript api call yourself - you either have an anchor tag of the appropriate class present before you load widgets.js and rely on it walking your DOM (the examples below are for the follow button, but that's only because the docs for the follow button are a little more explicit than that for the tweet button)

  <a href="http://twitter.com/twitterapi" class="twitter-follow-button" data-show-count="false">Follow @twitterapi</a>
  <script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>

or, if you want to create a button after widgets.js has been loaded (any sort of dynamic use), then you're supposed to do this by adding an iframe with appropriate url and parameters and it will return code that creates the button

<iframe allowtransparency="true" frameborder="0" scrolling="no"
  style="width:300px; height:20px;"></iframe>

See

I couldn't find any mention in the docs of building them by calls to exposed APIs in widgets.js itself (this may be just my inability to read docs of course)

--
T

Arnaud Meunier

unread,
Jun 6, 2011, 12:29:35 PM6/6/11
to twitter-deve...@googlegroups.com
Hey Andrew

As Tim said, we never documented / talked about this "manual" JavaScript rendering technique. You should not rely on that kind of hacks, as we might change the "widget.js" source code at any time. If you need to render the Tweet (or Follow) Button after the DOM has loaded, you should use the IFRAME version. That way, you'll be sure your code won't break :)

Hope that helps,
Arnaud / @rno



T

--
Twitter developer documentation and resources: https://dev.twitter.com/doc
API updates via Twitter: https://twitter.com/twitterapi
Issues/Enhancements Tracker: https://code.google.com/p/twitter-api/issues/list
Change your membership to this group: https://groups.google.com/forum/#!forum/twitter-development-talk

Andrew Dahl

unread,
Jun 6, 2011, 1:13:18 PM6/6/11
to twitter-deve...@googlegroups.com
Thanks guys. I will give the IFRAME version a shot.
Reply all
Reply to author
Forward
0 new messages