This repo contains multiple Spring Boot applications showcasing integration with Twitter REST APIs using different HTTP clients.
Twitter APIs provide different authentication methods, but this repo contains code to authenticate using application-only technique. In essence, we generate an App only access token(Bearer token) by passing the Twitter consumer key and consumer secret to the /token/oauth
endpoint.
The different modules use three different Twitter APIs
API | Description |
---|---|
POST https://api.twitter.com/oauth2/token |
Generate an access token (Bearer token) for app only |
GET https://api.twitter.com/2/users/by/username/{username} |
User details lookup by username |
GET https://api.twitter.com/2/users/{id}/liked_tweets |
List of liked tweets |
Make use of the Retrofit HTTP client for interfacing with the Twitter API. Spring Cloud provides an abstraction to Retrofit client with Spring Cloud Square dependency
Use the OpenFeign HTTP client for interfacing with the Twitter API. Spring Cloud provides an abstraction to OpenFeign with the Spring Cloud OpenFeign dependency
Also uses Spring Security OAuth Client to execute the client_credentails
flow for the Twitter API authentication
Use the Spring Webflux Webclient to perform the HTTP requests in a non-blocking, reactive programming way.
Similar to the OpenFeign module, this also uses Spring Security Oauth Client for executing the OAuth client credentials flow
Contains the core domain classes shared across all the above three modules.
Get access to the Twitter API by following the steps mentioned here