Skip to content

Instantly share code, notes, and snippets.

@NathanKleekamp
Created September 26, 2016 20:19
Show Gist options
  • Save NathanKleekamp/d6258730c622c4cdb1ca27ef5dac1c73 to your computer and use it in GitHub Desktop.
Save NathanKleekamp/d6258730c622c4cdb1ca27ef5dac1c73 to your computer and use it in GitHub Desktop.
Twitter timeline widget embed via js
<html>
<head>
<title>Twitter User Timeline Widget</title>
<script>
// I found Twitter's documentation for the user timeline a bit difficult
// to follow. Here's a very basic working example for others who might
// also struggle with it
// First, include the twitter wiget.js before anything that might require
// it. The docs recommend including it directly in the page template
window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
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"));
</script>
</head>
<body>
<div id="twitter-timeline"></div>
<script>
// Instantiate your widget
(function() {
// See https://dev.twitter.com/web/javascript/creating-widgets#create-timeline
var dataSource = {
sourceType: 'profile',
screenName: 'twitterdev'
};
// Your HTML element's ID
var target = document.getElementById('twitter-timeline');
// See https://dev.twitter.com/web/embedded-timelines/parameters
var options = {
chrome: 'nofooter',
height: 800,
width: 500
};
twttr.ready(function(twttr) {
twttr.widgets.createTimeline(dataSource, target, options);
});
})()
</script>
</body>
</html>
@taylorchasewhite
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment