Last active
February 7, 2023 21:46
-
-
Save jailbirt/3b6fa52c4621718646e7252b74172970 to your computer and use it in GitHub Desktop.
retrieveLastTweet.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if ! command -v jq > /dev/null; then sudo apt-get install -y jq; fi | |
# How many tweets to get | |
COUNT=1 | |
# Set the API endpoint and user to retrieve timeline for | |
API_ENDPOINT="https://api.twitter.com/1.1/statuses/user_timeline.json" | |
# Replace with the user | |
USER="" | |
# Replace with your own API credentials | |
API_KEY="" | |
API_SECRET="" | |
# Create a bearer token | |
BEARER_TOKEN=$(echo -n "$API_KEY:$API_SECRET" | base64) | |
# Get a bearer token | |
ACCESS_TOKEN=$(curl -s -u "$API_KEY:$API_SECRET" --data "grant_type=client_credentials" "https://api.twitter.com/oauth2/token" | jq -r '.access_token') | |
# Make a GET request to the API | |
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" "$API_ENDPOINT?screen_name=$USER&count=$COUNT"| jq '.[0].text' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
retrieve last public tweets from a specific user. only requires jq.