Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fermanjj/rust-twitter-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

Rust Twitter Bot

Basic Twitter Oauth2 steps

Oauth2 Twitter Docs

Following these steps got an Oauth2 access token

Hit this URL

  • CLIENT_ID Example: M1M5R3BMVy13QmpScXkzTUt5OE46MTpjaQ

  • REDIRECT_URI Example: https://2xdzlqwmizkelr7naddet3nqau0gpuzd.lambda-url.us-east-1.on.aws/

Get the code from the query string params

  • Example: MHk2RzZVdTcyaEVwVFFuS1RRendfLXBGVl9OQUNGNlZPa0Iwa1BWeWFKSEliOjE2NjA4Njg5NjI4NDg6MToxOmFjOjF

Next send a request like so

curl --location --request POST 'https://api.twitter.com/2/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic BASE64ENCODED'\
--data-urlencode 'code=CODE' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'redirect_uri=REDIRECT_URI' \
--data-urlencode 'code_verifier=challenge'
  • In the auth header goes a base64 encoded CLIENT_ID:CLIENT_SECRET

From that response you should get this

{
 "token_type": "bearer",
 "expires_in": 7200,
 "access_token": "ACCESS_TOKEN",
 "scope": "follows.read offline.access tweet.write users.read tweet.read",
 "refresh_token": "REFRESH_TOKEN"
}

Using the refresh token we can make a request like this to get another set of tokens

curl --location --request POST 'https://api.twitter.com/2/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic BASE64ENCODED'\
--data-urlencode 'refresh_token=REFRESH_TOKEN'\
--data-urlencode 'grant_type=refresh_token' 

Building and pushing Image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /