Skip to content

Instantly share code, notes, and snippets.

@dtsn
Created November 2, 2012 10:02
Show Gist options
  • Save dtsn/3999885 to your computer and use it in GitHub Desktop.
Save dtsn/3999885 to your computer and use it in GitHub Desktop.
Twitter Embed - Using the oEmbed format this piece of code will fetch the oEmbed object from twitter for a given status ID and will call your callback with the data
/*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true,
unused:true, curly:true, browser:true, indent:4, maxerr:50, globalstrict:false */
/**
* Will fetch the Twitter embed object
*
* See https://dev.twitter.com/docs/embedded-tweets for more information
*
* @param {Int} id Twitter status ID
* @param {Function} callback The callback function when this is successful
*/
var tweetEmbed = (function (id, callback) {
"use strict";
var url = 'https://api.twitter.com/1/statuses/oembed.json?id=' + id + '&callback=',
fn = 'TE_' + Date.now();
url += fn;
window[fn] = function (data) {
document.body.removeChild(script);
callback(data);
};
var script = document.createElement('script');
script.type = "text/javascript";
script.src = url;
document.body.appendChild(script);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment