Skip to content

Instantly share code, notes, and snippets.

@joeymink
Created April 9, 2014 13:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeymink/10271310 to your computer and use it in GitHub Desktop.
Save joeymink/10271310 to your computer and use it in GitHub Desktop.
Bash script to display a user's last tweet
#!/bin/bash
function usage {
echo "Usage:"
echo "last_tweet.sh <api key> <api secret> <username>"
exit 1
}
if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then
usage
fi
KEY=$1
SECRET=$2
USER=$3
APP_CREDS=`echo -n "$KEY:$SECRET" | base64`
curl --silent --header "Authorization: Basic $APP_CREDS" --data "grant_type=client_credentials" https://api.twitter.com/oauth2/token > bearer_resp.json
BEARER=`grep access_token\":\"[^\"]* bearer_resp.json --only-matching | sed s/access_token\":\"//g`
# https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
curl --silent --header "Authorization: Bearer $BEARER" https://api.twitter.com/1.1/statuses/user_timeline.json?count=1\&screen_name=$USER > user_timeline.json
LAST_TWEET=`grep text\":\"[^\"]* user_timeline.json --only-matching | sed s/text\":\"//g`
echo "Last tweet was:"
echo $LAST_TWEET
@PterPmnta
Copy link

Sorry, this work for runbook in azure

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