Get tweets with Javascript

  1. Go to www.twitter.com 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 = "//cdn.syndication.twimg.com/widgets/timelines/" + 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;
c.style.display="none";
document.body.appendChild(c);
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');
for(i=0;i
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.
console.log(o);
});
}
// 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

https://nubilescash.com/feed/contentZips/type/photos/format/pipe/dateFrom/2021-04-27/attributes/url/

How To Build A Simple Star Rating System

How to convert a web page into PDF format using renderAs attribute

Introduction to Window localStorage

Phase II Progress Report — New functionality — scriptable object waves

https://www.instagram.com/tv/CYcZyZTAiaf/?utm_medium=copy_link

Finding Nearby Places with using Places API in React Native

Micro Frontends in A Nutshell

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
MicroPyramid

MicroPyramid

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

More from Medium

JavaScript Object Oriented Programming | Part 1

JavaScript Events

Javascript Array Methods Cheatsheet

Introduction to JavaScript