Created
November 2, 2012 10:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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