user482024
user482024

Reputation: 95

Embed multiple tweets on one page via individual ids

I am trying to figure out a way with twitter's new guidelines that will allow me to embed specific tweets from different users dynamically into a webpage. I have looked at Twitter's oEmbed endpoint and it seems like what I need, however I am not sure how to accomplish this via one ajax call.

I obviously do not want to make tons of calls to the Twitter server and max out, so is there a way to run a loop inside a ajax call to try different tweet ids without hitting the server multiple times?

Or is there another method I am not familiar with that someone could suggest?

I hope this is clear enough of a question, thanks for taking the time to read.

cheers

$(document).ready(function(){ 
var output = $("#output");
var ids = [ php code to build an array of IDs];

for(i=0; i<ids.length; i++){
   $.ajax({
 url: 'https://api.twitter.com/1/statuses/oembed.json?id=' + ids[i] + '&align=center&callback=?',
 dataType: 'json',
 success: function(data) {
  $(data.html).appendTo(output);
    }
      });
}
});

Upvotes: 1

Views: 3493

Answers (1)

user482024
user482024

Reputation: 95

For anyone that is interested, the way i've accomplished this is to seek out and store the embedded tweet html blockquote into a database and just pump them out one by one...

for instance..

<blockquote class="twitter-tweet"><p>RT @<a href="https://twitter.com/nosherwan">nosherwan</a>: Enyojs of webOS fame is now open source and looks like a serious contender for multi platform application development</p>&mdash; Enyo (@EnyoJS) <a href="https://twitter.com/EnyoJS/status/263664668839645184" data-datetime="2012-10-31T15:32:10+00:00">October 31, 2012</a></blockquote>

Adding in the script tag once.

<script src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

Hope it helps someone.

Upvotes: 3

Related Questions