Skip to content

Instantly share code, notes, and snippets.

@iamdaniele
Created August 29, 2019 22:53
Show Gist options
  • Save iamdaniele/a2380f633c48b7dcb7ad88f8ec4fc09b to your computer and use it in GitHub Desktop.
Save iamdaniele/a2380f633c48b7dcb7ad88f8ec4fc09b to your computer and use it in GitHub Desktop.
Get Bearer Token (shell function)
function bearer_token () {
local CONSUMER_API=$1
local CONSUMER_SECRET=$2
if [ -z "$CONSUMER_API" ] || [ -z "$CONSUMER_SECRET" ] ; then
echo "Usage: ${FUNCNAME[0]} <consumer_api_key> <consumer_secret>"
return 1
fi
curl -s -XPOST -H "Authorization: Basic $(echo -n $CONSUMER_API:$CONSUMER_SECRET | base64)" -H "Content-type: application/x-www-form-urlencoded; charset: utf-8" -d "grant_type=client_credentials" https://api.twitter.com/oauth2/token | jq -r .access_token
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment