Giter Club home page Giter Club logo

twitter-oauth-by-example-in-nodejs's Introduction

twitter-oauth-by-example-in-nodejs

Create an app on developer.twitter.com and get the following key and tokens:

  • TWITTER_ACCESS_KEY
  • TWITTER_ACCESS_TOKEN_SECRET
  • TWITTER_CONSUMER_KEY
  • TWITTER_CONSUMER_SECRET

and run in your cloned local repository (to clone the repo: git clone [email protected]:christian-fei/twitter-oauth-by-example-in-nodejs.git):


TWITTER_ACCESS_KEY=[YOUR_TWITTER_ACCESS_KEY] TWITTER_ACCESS_TOKEN_SECRET=[YOUR_TWITTER_ACCESS_TOKEN_SECRET] TWITTER_CONSUMER_KEY=[YOUR_TWITTER_CONSUMER_KEY] TWITTER_CONSUMER_SECRET=[YOUR_TWITTER_CONSUMER_SECRET] npm start

this will log something like:


> [email protected] start /Users/christian/Documents/projects/twitter-oauth-by-example-in-nodejs
> node $npm_package_main

oauth1 response {"id":2244994945,"id_str":"2244994945","name":"Twitter Dev","screen_name":"TwitterDev","location":"1...
oauth2 response {"id":2244994945,"id_str":"2244994945","name":"Twitter Dev","screen_name":"TwitterDev","location":"1...

check out the source code and step by step explanation on christianfei.com

sidenote: OAuth2 with curl

Getting an access token that can be used to authenticate via Bearer authentication can be easily achieved with curl:

curl -u '<YOUR_TWITTER_CONSUMER_KEY>:<YOUR_TWITTER_CONSUMER_SECRET>' --data 'grant_type=client_credentials' 'https://api.twitter.com/oauth2/token'

and the response will look something like this:

{"token_type":"bearer","access_token":"AAAAAAAAA..."}

Now we can authenticate with the access_token to the twitter api, using Bearer authorization scheme:

curl --header 'Authorization: Bearer AAAAAAAAA...' 'https://api.twitter.com/1.1/users/show.json?screen_name=christian_fei'

returning more information about the twitter user profile christian_fei:

{"id":128166532,"id_str":"128166532","name":"\/christian\/\ud83c\udf55","screen_name":"christian_fei","location":"The Internet","profile_location":null,"description":"agile person, clean code connoisseur and testing aficionado \ud83d\udc68\u200d\ud83d\udcbb dev @wonderflow","url":"https:\/\/t.co\/qUleUCEuNH","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/qUleUCEuNH","expanded_url":"https:\/\/christianfei.com\/","display_url":"christianfei.com","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":567,"friends_count":133,"listed_count":111,"created_at":"Wed Mar 31 08:55:25 +0000 2010","favourites_count":4078,"utc_offset":null,"time_zone":null,"geo_enabled":true,"verified":false,"statuses_count":12795 ...

twitter-oauth-by-example-in-nodejs's People

Contributors

christian-fei avatar

Stargazers

 Kinza Khokhar avatar Muhammad Shahzad Ali avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

gabriel-son

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.