Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

React.js Twitter API Tutorial to Embed Profile & Timeline, Hashtags of User in Browser Using Javascript

Posted on March 8, 2023

 

Welcome folks today in this blog post we will be using the react-twitter-widgets library inside the react.js to embed the user tweets and timeline in browser using javascript. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

In order to get started you need to make a new react.js project using the below command

 

 

npx create-react-app twitterapp

 

 

cd twitterapp

 

 

Now you need to install the below library using the npm command as shown below

 

 

npm i react-twitter-widgets

 

 

And after that you need to copy paste the below code inside the App.js file

 

 

Showing Tweet of User

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import './App.css';
import {Tweet } from 'react-twitter-widgets'
 
 
function App() {
  return (
    <div className="App">
      <Tweet tweetId="841418541026877441" options={{theme:"dark",align:"center",width:"200"}} />
/>
    </div>
  );
}
 
export default App;

 

 

As you can see we are importing the tweet component from the library and here we are passing the tweetId and also the theme option which can be either dark or light and then we are centering the tweet and providing fixed width to it.

 

 

 

 

Showing Timeline of Twitter Username

 

 

Now we can pass the username of twitter using the below component to show the timeline of tweets as shown below

 

 

App.js

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import './App.css';
import { Timeline } from 'react-twitter-widgets'
 
 
function App() {
  return (
    <div className="App">
      <Timeline
  dataSource={{
    sourceType: 'profile',
    screenName: 'blackcaps'
  }}
  options={{
    height: '400'
  }}
/>
    </div>
  );
}
 
export default App;

 

 

 

 

 

Follow and Share Buttons

 

 

Now you can very easily show the follow and share buttons inside your own website of twitter. Whenever someone clicks on them it will be redirected to your twitter profile as shown below

 

 

App.js

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import './App.css';
import { Follow,Share } from 'react-twitter-widgets'
 
 
function App() {
  return (
    <div className="App">
  
<Follow username="reactjs" options={{ size: "large" }} />
 
<Share url='https://webninjadeveloper.com' options={{size:'large',text:"Share my Website"}} />
 
 
    </div>
  );
 
}
 
export default App;

 

 

As you can see we are passing the url that we want to share and also the size of the button and also the text which will be written to share your website. And then for the follow button you need to replace your own twitter username so that users can follow you.

 

 

 

 

 

 

 

Hashtag Button

 

 

Now you can even tweet with a certain number of hashtags using this below code

 

 

App.js

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import './App.css';
import { Hashtag } from 'react-twitter-widgets'
 
 
function App() {
  return (
    <div className="App">
 
<Hashtag hashtag='javascript' options={{size:'large'}} />
 
 
    </div>
  );
 
}
 
export default App;

 

 

 

 

Recent Posts

  • React.js Twitter API Tutorial to Embed Profile & Timeline, Hashtags of User in Browser Using Javascript
  • Android Java Tutorial to Change Styles & Visibility of System Bars (Top, Action & Status) Full Example
  • Android Java Project to Display & Play Audio Files From Storage inside ListView Using MediaPlayer Class
  • Android Java Project to Build MP4 Video to MP3 Audio Converter Using MediaMuxer Class
  • Android Java Project to Merge Multiple PDF Documents From Gallery Using iTextPDF Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme