By providing only a status ID or a URL, I simply want a tweet status nicely to be rendered (i.e. in Twitter cards format) in my iPython Notebook. This can easily be achieved in WordPress simply by putting the link into the post.
First, tried the embed code provided by Twitter, which appears when 'more'>'embed tweet' button on the status page clicked. Successfully inserted into the NB but the embed code contains the tweet text (I don't want to go to twitter status page and click buttons for every tweet I want to display, instead looking for a way to automate this process):
HTML('<blockquote class="twitter-tweet" lang="en"><p>Sen. Joni Ernst of Iowa is set to give the Republican response to the President's <a href="https://twitter.com/hashtag/CNNSOTU?src=hash">#CNNSOTU</a>. <a href="http://t.co/PXWVbNsWXp">http://t.co/PXWVbNsWXp</a></p>— CNN Breaking News (@cnnbrk) <a href="https://twitter.com/cnnbrk/status/557737268488974338">January 21, 2015</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>')
Second, tried to import with iFrame, but this returned an empty iframe:
HTML('<iframe src=https://twitter.com/cnn/status/557737452346294274 width=700 height=350></iframe>')
with this error message (note: I also tried appending &output=embed
to the url as suggested) :
Refused to display 'https://twitter.com/cnn/status/557737452346294274' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
Third, tried including Twitter's widgets.js script to NB as suggested :
from IPython.display import Javascript
Javascript('window.twttr = (function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; 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); t._e = []; t.ready = function(f) { t._e.push(f); }; return t; }(document, "script", "twitter-wjs"));')
And expected to see by calling (this is probably where I'm doing wrong) :
HTML('<iframe src=https://api.twitter.com/1.1/statuses/oembed.json?id=557737268488974338></iframe>')
But got this error instead :
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
This should be something very simple. That is probably why it has not already been asked on SO. I am not experienced in JS, so please take this into account in your answers. Thanks.