Skip to content

Instantly share code, notes, and snippets.

@jailbirt
Last active February 7, 2023 21:46
Show Gist options
  • Save jailbirt/3b6fa52c4621718646e7252b74172970 to your computer and use it in GitHub Desktop.
Save jailbirt/3b6fa52c4621718646e7252b74172970 to your computer and use it in GitHub Desktop.
retrieveLastTweet.sh
#!/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'
@jailbirt
Copy link
Author

jailbirt commented Feb 7, 2023

retrieve last public tweets from a specific user. only requires jq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment