Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

tweet using bash

By: varDump on Apr 7th, 2012  |  syntax: Bash  |  size: 2.28 KB  |  views: 1,404  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2. #BashtweetScript
  3. #@lihashgnis
  4.  
  5. email='' #email or user name
  6. password=''
  7. tweet='' #text to tweet
  8.  
  9.  
  10. cookies='cookie.txt'
  11. user_agent='Firefox/10.0.2'
  12.  
  13. curl -X GET 'https://www.twitter.com' --verbose --user-agent "${user_agent}" --cookie $cookies --cookie-jar $cookies --location
  14.  
  15. curl -X POST 'https://twitter.com/sessions?phx=1' --verbose --user-agent "${user_agent}" --cookie $cookies --cookie-jar $cookies  --data-urlencode "session[username_or_email]=${email}" --data-urlencode "session[password]=${password}" --data-urlencode "return_to_ssl=true"
  16.  
  17. curl -X GET 'https://www.twitter.com' --verbose --user-agent "${user_agent}" --cookie $cookies --cookie-jar $cookies --location
  18.  
  19. rethtml=$(curl -X GET 'https://twitter.com/#!/lihashgnis' --verbose --user-agent "${user_agent}" --cookie $cookies --cookie-jar $cookies)
  20.  
  21. echo "####################################################################"
  22.  
  23. #do read next two comments
  24. <<comment1
  25.  IMP- at this stage we have the cookies that we can use to authenticate ourselves However twitter also expects one more parameter for submitting stutus , postAuthenticityToken... which can be obtained by parsing the html ofpostAuthenticityToken
  26. user,s profile page
  27. comment1
  28.  
  29. <<comment2
  30. what ret2=${rethtml##*\"postAuthenticityToken\":\"} does is that it strips
  31.  all content from the rethtml variable till last place where it finds
  32.  postAuthenticityToken and then line following that code strips text till
  33.  ","deciderFeatures" , so now we are left with only the value of
  34.  postAuthenticityToken ... looking at the source of users page and finding
  35.  these two words will give a better understanding of how this works...
  36.  details about how striping is done using pund and percent symbols can be
  37.  found at http://linuxgazette.net/issue18/bash.html
  38. comment2
  39.  
  40. ret2=${rethtml##*\"postAuthenticityToken\":\"}
  41. post_authenticity_token=${ret2%%\"\,\"deciderFeatures\":*}
  42.  
  43. curl -X POST 'https://api.twitter.com/1/statuses/update.json' --header "X-Requested-With:XMLHttpRequest" --header "Host:api.twitter.com" --header "X-PHX:true" --verbose --user-agent "firefox/3.5" --cookie cookie.txt --cookie-jar cookie.txt --data-urlencode "include_entities=true" --data-urlencode "status=${tweet}" --data-urlencode "post_authenticity_token=${post_authenticity_token}"
clone this paste RAW Paste Data