Last active
August 15, 2020 14:43
-
-
Save iworker/d7ce57a5ac5575a0c22ce7128884c6dd to your computer and use it in GitHub Desktop.
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 | |
METHOD=GET | |
URL="https://api.twitter.com/1.1/users/search.json" | |
QUERY="🏳" | |
OAUTH_APP_KEY=<APP_KEY> | |
OAUTH_APP_SECRET=<APP_SECRET> | |
OAUTH_TOKEN=<OAUTH_TOKEN> | |
OAUTH_TOKEN_SECRET=<OAUTH_TOKEN_SECRET> | |
OAUTH_VERSION="1.0" | |
OAUTH_SIGNATURE_METHOD="HMAC-SHA1" | |
TIMESTAMP=$(date +%s) | |
OAUTH_NONCE=$(md5 -qs "${TIMESTAMP}${RANDOM}") | |
HTTP_QUERY=$(php -r "echo rawurlencode('$QUERY');") | |
HTTP_URL=$(php -r "echo rawurlencode('$URL');") | |
QUERY_STRING="oauth_consumer_key=${OAUTH_APP_KEY}&oauth_nonce=${OAUTH_NONCE}&oauth_signature_method=${OAUTH_SIGNATURE_METHOD}&oauth_timestamp=${TIMESTAMP}&oauth_token=${OAUTH_TOKEN}&oauth_version=${OAUTH_VERSION}&q=${HTTP_QUERY}" | |
HTTP_QUERY_STRING=$(php -r "echo rawurlencode('$QUERY_STRING');") | |
SIGNATURE_BASE="${METHOD}&${HTTP_URL}&${HTTP_QUERY_STRING}" | |
SIGNATURE_KEY="${OAUTH_APP_SECRET}&${OAUTH_TOKEN_SECRET}" | |
OAUTH_SIGNATURE=$(echo -n "$SIGNATURE_BASE" | openssl dgst -sha1 -hmac "$SIGNATURE_KEY" -binary | base64) | |
HTTP_OAUTH_SIGNATURE=$(php -r "echo rawurlencode('$OAUTH_SIGNATURE');") | |
curl -X ${METHOD} -H 'Accept: application/json' -H "Authorization: OAuth oauth_version=\"${OAUTH_VERSION}\", oauth_nonce=\"${OAUTH_NONCE}\", oauth_timestamp=\"${TIMESTAMP}\", oauth_consumer_key=\"${OAUTH_APP_KEY}\", oauth_token=\"${OAUTH_TOKEN}\", oauth_signature_method=\"${OAUTH_SIGNATURE_METHOD}\", oauth_signature=\"${HTTP_OAUTH_SIGNATURE}\"" \ | |
"$URL?q=$HTTP_QUERY" > raw_output.json | |
php -r "echo json_encode(json_decode(file_get_contents('raw_output.json'), true), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment