|
| 1 | +`stweet` (aka. `ShellTweet`) |
| 2 | +--- |
| 3 | + |
| 4 | +A simple shell script to post tweets to your timeline using Twitter's v1.1 API. |
| 5 | + |
| 6 | +* Do you live in your CLI? |
| 7 | +* Rather not switch to a browser or other device to broadcast to the world? |
| 8 | +* Wanna automate tweets of whatever gibberish via cron? |
| 9 | + |
| 10 | +If yes to any of the above, then `stweet`! |
| 11 | + |
| 12 | +So, this is just the beginning! `ShellTweet` suggestions and pull requests are welcome and encouraged. |
| 13 | + |
| 14 | +## Requirements |
| 15 | + |
| 16 | +Linux Based OS/Virtual Environment |
| 17 | + |
| 18 | +`AND` |
| 19 | + |
| 20 | +PHP >= 5.3.x |
| 21 | + |
| 22 | +`OR` |
| 23 | + |
| 24 | +OpenSSL |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +Why PHP or OpenSSL? |
| 29 | + |
| 30 | +Well, the signature for authorizing and posting the status update is calculated by passing the signature base string and signing key to the HMAC-SHA1 hashing algorithm. The details of the algorithm are explained in depth [HERE](http://en.wikipedia.org/wiki/HMAC), but thankfully there are implementations of HMAC-SHA1 available for every popular language. For example, PHP has the [hash_hmac function](http://php.net/manual/en/function.hash-hmac.php) and HMAC-SHA1 hashing can easily be generated on almost any modern Unix-like system using [OpenSSL](http://www.openssl.org/docs/apps/dgst.html). |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +* Hashing defaults to PHP if both are installed. |
| 35 | + |
| 36 | +* On a production webserver, typically both would already be installed (see your host if you are unsure). |
| 37 | + |
| 38 | +* If using on your local box and you dont have a l/a/n/mp stack or stand-alone PHP install or OpenSSL, then get one. |
| 39 | + |
| 40 | +* A quick check: |
| 41 | + |
| 42 | + # Open up a linux terminal and type: |
| 43 | + |
| 44 | + ~$ which php openssl |
| 45 | + |
| 46 | + # If you have 1 or both installed, you should see something similar to: |
| 47 | + |
| 48 | + ~$ which php openssl |
| 49 | + /usr/local/bin/php |
| 50 | + /usr/bin/openssl |
| 51 | + |
| 52 | + # If you get nothing in return or see somthing like /usr/bin/which: no {SOFTWARE_NAME} in (/usr/local/bin:..... |
| 53 | + # for both php AND openssl, then you dont have either installed. |
| 54 | + |
| 55 | + |
| 56 | +## Configuration |
| 57 | + |
| 58 | +The goal of `stweet` is simplicity `PAUSE` You do however need to make yourself a twitter app! |
| 59 | + |
| 60 | +So basically, you need to: |
| 61 | + |
| 62 | +1. First, [go and create yourself a twitter app on the twitter developer site](https://dev.twitter.com/apps/). |
| 63 | +2. After creation, click the `Settings` tab, scroll down and enable read/write access for your twitter app. (This will take a min.) |
| 64 | +3. Now, click the `Details` tab, scroll down and click `Create my access token` (This will also take a min.) |
| 65 | +4. Lastly, click the `OAuth tool` tab and grab your consumer key/secret and access token/secret: |
| 66 | + |
| 67 | +  |
| 68 | + |
| 69 | +Ok, got all that? |
| 70 | + |
| 71 | +Now, open up `stweet` in your preferred editor and add your app access tokens (lines 132-135). |
| 72 | + |
| 73 | + 124 |
| 74 | + 125 ############# |
| 75 | + 126 # TWITTER API |
| 76 | + 127 # |
| 77 | + 128 # Your application's OAuth settings. |
| 78 | + 129 ##### [EDIT THIS TO YOUR APPLICATION'S VALUES] |
| 79 | + 130 |
| 80 | + 131 |
| 81 | + 132 app_key="YOUR_CONSUMER_KEY" |
| 82 | + 133 app_secret="YOUR_CONSUMER_SECRET" |
| 83 | + 134 access_token="YOUR_ACCESS_TOKEN" |
| 84 | + 135 access_secret="YOUR_ACCESS_SECRET" |
| 85 | + 136 |
| 86 | + |
| 87 | + |
| 88 | +All that's left is to just place `stweet` in your scripts, bin, or executable dir: |
| 89 | + |
| 90 | + ~$ cd /place/to/where/you/downloaded/stweet |
| 91 | + ~$ mv stweet /path/to/your/executable/scripts/ |
| 92 | + |
| 93 | +...or create a symlink to `stweet` in your scripts, bin, or executable dir: |
| 94 | + |
| 95 | + ~$ cd /path/to/your/executable/scripts/ |
| 96 | + ~$ ln -s /place/to/where/you/downloaded/stweet ./stweet |
| 97 | + |
| 98 | +**Done!** |
| 99 | + |
| 100 | +## How To `stweet` |
| 101 | + |
| 102 | +1. Tweet It. (A tweet oneliner) |
| 103 | + |
| 104 | + ~$ stweet this is pretty dope! |
| 105 | + |
| 106 | + # NOTE: ONLY if using this option (Option 1. - Direct tweet), |
| 107 | + # all "hastags" must be escaped with a '\' |
| 108 | + |
| 109 | + ~$ stweet \#money on my \#mind. |
| 110 | + |
| 111 | + # WHY: Linux will see it as a comment and ignore everything after the first "#" |
| 112 | + |
| 113 | + |
| 114 | +2. Prompt It. (Prompts you for your message) |
| 115 | + |
| 116 | + ~$ stweet |
| 117 | + What Are You Tweetin' [140 pls]: yep this is very simple #bashery |
| 118 | + |
| 119 | + |
| 120 | +3. Pipe It. (Feed stweet the stdout from another command or series of commands) |
| 121 | + |
| 122 | + ~$ cat somefile | stweet |
| 123 | + |
| 124 | + |
| 125 | +4. Cron It. (Automate your tweets) |
| 126 | + |
| 127 | + */5 * * * * PATH=PATH:/path/to/your/executable/scripts/; curl -s http://something.from/somewhere | stweet > /dev/null 2>&1 |
| 128 | + |
| 129 | + |
| 130 | +Yep. Pretty `stweet` right? |
| 131 | + |
| 132 | +If successful, you will see something like: |
| 133 | + |
| 134 | + ~$ stweet Ok. I can do this. \#osohappy |
| 135 | + |
| 136 | + Tweeted It! |
| 137 | + |
| 138 | + |
| 139 | +If an error occurs, it will be displayed in un-pretty (sorry) JSON: o_o |
| 140 | + |
| 141 | + ~$ stweet This is some text that is really long and not less than 140 characters. But it is something I really want to get off of my chest because it is important for me to say it! |
| 142 | + |
| 143 | + Error: [ {"errors":[{"code":186,"message":"Status is over 140 characters."}]} ] |
| 144 | + |
| 145 | +## Limitations |
| 146 | + |
| 147 | +This is a simple CLI tool. Nothing real extravagant here. |
| 148 | + |
| 149 | +It's primarily for text only tweets <= 140 characters and nothing more (at least currently). |
| 150 | + |
| 151 | +However, it's use can be expanded upon as you wish... ([Check the Twitter API docs](https://dev.twitter.com/docs/api/1.1/)). |
| 152 | + |
| 153 | +I'd love to see/merge what other `stweet` things you do with it. |
| 154 | + |
| 155 | +## OS's |
| 156 | + |
| 157 | +Tested and confirmed working on: |
| 158 | + |
| 159 | +* Mac OSX 10.9.1 |
| 160 | +* CentOS 6.4 |
| 161 | +* CentOS 5.10 |
| 162 | +* More to come... |
| 163 | + |
| 164 | +If working for you (or not) and your OS is not mentioned, please drop me a line with your OS/Environment. |
| 165 | + |
| 166 | +## License |
| 167 | + |
| 168 | +[MIT License](http://api.marquelmedia.net/lic/LICENSE.md) |
| 169 | + |
| 170 | + |
0 commit comments