Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #BashtweetScript
- #@lihashgnis
- email='' #email or user name
- password=''
- tweet='' #text to tweet
- cookies='cookie.txt'
- user_agent='Firefox/10.0.2'
- curl -X GET 'https://www.twitter.com' --verbose --user-agent "${user_agent}" --cookie $cookies --cookie-jar $cookies --location
- 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"
- curl -X GET 'https://www.twitter.com' --verbose --user-agent "${user_agent}" --cookie $cookies --cookie-jar $cookies --location
- rethtml=$(curl -X GET 'https://twitter.com/#!/lihashgnis' --verbose --user-agent "${user_agent}" --cookie $cookies --cookie-jar $cookies)
- echo "####################################################################"
- #do read next two comments
- <<comment1
- 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
- user,s profile page
- comment1
- <<comment2
- what ret2=${rethtml##*\"postAuthenticityToken\":\"} does is that it strips
- all content from the rethtml variable till last place where it finds
- postAuthenticityToken and then line following that code strips text till
- ","deciderFeatures" , so now we are left with only the value of
- postAuthenticityToken ... looking at the source of users page and finding
- these two words will give a better understanding of how this works...
- details about how striping is done using pund and percent symbols can be
- found at http://linuxgazette.net/issue18/bash.html
- comment2
- ret2=${rethtml##*\"postAuthenticityToken\":\"}
- post_authenticity_token=${ret2%%\"\,\"deciderFeatures\":*}
- 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}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement