LoginSignup
0
0

More than 5 years have passed since last update.

webサービス利用でshellでtweetする

Posted at

shellからtwitterにpostしたい

このサービスを利用してツイートをさせる。
http://stewgate-u.appspot.com/

ツイート元にしたいTwitterアカウントでログインしてTokenを発行する。

Tokenを環境変数に定義する

用途に応じて適当なところに取得したTOKENを定義
/etc/environment
/etc/profile
~/.bash_profile
~/.bashrc

今回は自分のRaspberryPiの起動時にTweetしてもらいたいので以下の定義をした。

/etc/environment
export STREWGATE_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxx

shellscript

140文字に切って、POSTするだけのかんたんなスクリプト

tweet
#!/bin/sh
#
TWEET=$(echo "$*"|cut -c -140)
curl -X POST --silent --data "_t=${STREWGATE_TOKEN}" --data-urlencode "msg=${TWEET}" http://stewgate-u.appspot.com/api/post/ > /dev/null

動作確認

pi@raspberrypi:~ $ tweet お前も蝋人形にしてやろうか!!!

tweet.png

備考

同じ文字列を連続してTweetは出来ないよ。(Twitter側の仕様っぽい)
適当に動作させるには手軽で良いサービスですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0