Using OAuth2 to Post a tweet On Twitter

If API is already deprecated, please report it by using this button


Provide the easiest way (less than 15 lines of code) to use OAuth to share a post or link on a LinkedIn account on behalf of a LinkedIn user using Javascript.

Code Example

Here is the final code - a Javascript snippet that you can tweak, and play around with instantly without any coding, configuration, etc.

Code Explanation:


<a id="twitter-button" class="btn btn-block btn-social btn-twitter">
  <i class="fa fa-twitter"></i> Post a Tweet on Twitter




$('#twitter-button').on('click', function() {
    // Initialize with your app public key
  // Use popup for OAuth
  OAuth.popup('twitter').then(twitter => {
    //Twitter provider object
    alert('You can check Twitter provider object in the console!');
    console.log('twitter:', twitter);{
    }).then(tweet => {
        alert('You can find created Tweet in both console and your Twitter account!');
      console.log('Created Tweet:', tweet);

External Requirements

This Javascript code has external requirements:

Step-by-step Guide

Here is a summary of the steps to create this social button to post a Tweet on Twitter on a user's behalf using OAuth2:

  1. Create a Twitter account, if you do not have one
  2. Create an app on Twitter using this simple step-by-step guide
  3. Copy your Twitter app client id and client secret
  4. Signup for account
  5. Link your Twitter app with by pasting your Twitter app client id and client secret into
  6. Copy the OAuth javascript snippet ( on to your web page

Live example code for using OAuth to Post a tweet via Twitter

Use Line OAuth to:

Use Apple OAuth to:

Use Meetup OAuth to:

Use Snapchat OAuth to:

Use Facebook OAuth to: