Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oembed not rendering javascript, only text for Twitter

I am using oembed in the Twitter API to embed a tweet widget. It gets the JSON response just fine, but it shows the tweet in text only, not the embedded widget response. The javascript that Twitter sends is not firing.

  $(document).ready(function() 

  {$.getJSON("https://api.twitter.com/1/statuses/oembed.json?id=133640144317198338&align=center&callback=?", function(data)
    {$('#target').html(data.html);
    });
  });

then for the html:

<body >
  <div id="target"></div>
</body>

=================================================================

Response comes formatted in text only version, instead of the widget.

like image 316
HeatherSpence Avatar asked Dec 10 '12 09:12

HeatherSpence


2 Answers

I was stuck with this as well. If you don't want to deal with jquery you can just use

<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>

and then put into html:

<blockquote class="twitter-tweet"><a href="http://twitter.com/coffee_dad/status/287348974577385474">link</a></blockquote>

I'm not sure if this is the proper way, but it seems to work for me.

like image 175
dranxo Avatar answered Oct 31 '22 11:10

dranxo


I had the same problem. The dynamically loaded blockquote from oembed won't get rendered. After digging into widget.js, I found that you just need to call twttr.widgets.load() after you have added new blockquote into your page. Enjoy!

like image 25
Falcon Avatar answered Oct 31 '22 11:10

Falcon