Get tweets with Javascript

  1. Go to and sign in then go to your settings page.
  2. Go to “Widgets” on the left hand side.
  3. Create a new widget as you like.
  4. Check “exclude replies” if you dont want replies in results.
  5. Now go back to settings -> widgets page, you will see the widget you just created. Click edit.
  6. Now look at the URL in your web browser, you will see a long number like this: 441110970094473216.
  7. Use this as your ID below!
var tw = function () {
return {
fetch: function (twid, tc, cbf) {
(tweets_count=tc, cbfunc = cbf, c = document.createElement("script"), c.type = "text/javascript", c.src = "//" + twid + "?&lang=en&callback=tw.callback&suppress_response_codes=true&rnd=" + Math.random(), document.getElementsByTagName("head")[0].appendChild(c))
callback: function (e) {
var c = document.createElement("div");
c.setAttribute("id", "twitter-stage");
c.innerHTML = e.body;"none";
var tweet_json = [];
usr_imgs = document.querySelectorAll('#twitter-stage div ol.h-feed li div.header div a.u-url.profile img.u-photo.avatar');
usr_names = document.querySelectorAll('#twitter-stage ol li div.header span.full-name span');
usr_screen_names = document.querySelectorAll('#twitter-stage ol li div.header a.u-url.profile span b');
tweets = document.querySelectorAll('#twitter-stage ol li div.e-entry-content p.e-entry-title');
dates = document.querySelectorAll('#twitter-stage ol.h-feed li div.header a time');
tweetids = document.querySelectorAll('#twitter-stage ol.h-feed li div ul li:first-of-type a');
Now include the file and use it as followingfunction tweets(tws){
$.each(tws, function(i,o){
// You can do as you wish with the values in 'o' objects.
// this will fetch tweets of the given widget id and pass the tweets to tweets function
tw.fetch('441110970094473216', 20, tweets);
This is much straight forward approach, you can extend it as you like.

The article was originally published at MicroPyramid blog.




Python, Django, Android and IOS, reactjs, react-native, AWS, Salesforce consulting & development company

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Some Reasons for Disliking React Hooks

A Beginners Guide to Understanding Redux

Create a CRUD Rest API with Node and Express.js

Global State Management in an Electron Application using Pinia and Vue.js

State Management in an Electron Application

Lessons Learned Working With React

6 Productivity Tools for Front-end Developers

12 Ways Programmers Think Differently From Others

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Python, Django, Android and IOS, reactjs, react-native, AWS, Salesforce consulting & development company

More from Medium

Javascript — Create a simple server with Express

JavaScript Basics #6: The Document Object Model

Hoisting in JavaScript A-Z

What’s new in javascript? — ES 2021