twitter-oauth-timeline.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. # Klimbim Software collection, A bag full of things
  3. # Copyright (C) 2011-2023 Johannes 'Banana' Keßler
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. # 2013 http://www.bananas-playground.net
  18. # fetch the timeline from given twitter user
  19. # based on :
  20. # https://github.com/gianu/latest_tweets/blob/master/latest_tweets.sh
  21. # https://dev.twitter.com/discussions/14460
  22. #
  23. TIMESTAMP=`date +%s`;
  24. NONCE=`date +%s%T%N | openssl base64 | sed -e s'/[+=/]//g'`
  25. SCREEN_NAME="YOUR_TWITTER_NAME";
  26. TWEET_COUNT=10;
  27. OUTPUT_FILE="/path/to/output.json"
  28. CONSUMER_KEY="YOUR_CONSUMER_KEY"
  29. CONSUMER_SECRET="YOUR_CONSUMER_SECRET"
  30. OAUTH_TOKEN="YOUR_OAUTH_TOKEN"
  31. OAUTH_SECRET="YOUR_OUTH_SECRET"
  32. signature_base_string="GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fuser_timeline.json&count%3D${TWEET_COUNT}%26oauth_consumer_key%3D${CONSUMER_KEY}%26oauth_nonce%3D${NONCE}%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D${TIMESTAMP}%26oauth_token%3D${OAUTH_TOKEN}%26oauth_version%3D1.0%26screen_name%3D${SCREEN_NAME}"
  33. signature_key="${CONSUMER_SECRET}&${OAUTH_SECRET}"
  34. oauth_signature=`echo -n ${signature_base_string} | openssl dgst -sha1 -hmac ${signature_key} -binary | openssl base64 | sed -e s'/+/%2B/' -e s'/\//%2F/' -e s'/=/%3D/'`
  35. header="Authorization: OAuth oauth_consumer_key=\"${CONSUMER_KEY}\", oauth_nonce=\"${NONCE}\", oauth_signature=\"${oauth_signature}\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"${TIMESTAMP}\", oauth_token=\"${OAUTH_TOKEN}\", oauth_version=\"1.0\""
  36. wget -q --cache=off --output-document="${OUTPUT_FILE}" "https://api.twitter.com/1.1/statuses/user_timeline.json?count=${TWEET_COUNT}&screen_name=${SCREEN_NAME}" --header "Content-Type: application/x-www-form-urlencoded" --header "${header}";