Created
April 9, 2014 13:35
-
-
Save joeymink/10271310 to your computer and use it in GitHub Desktop.
Bash script to display a user's last tweet
This file contains hidden or 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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, this work for runbook in azure