You need to prepare API keys at first.Go to the front page, create a new app, and generate a new access token.
Then put them as a key file at ~/.tweet.client.key
, with the format:
MY_SCREEN_NAME=xxxxxxxxxxxxxxxxxxx
MY_LANGUAGE=xx
CONSUMER_KEY=xxxxxxxxxxxxxxxxxxx
CONSUMER_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ACCESS_TOKEN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
If there is a key file named tweet.client.key
in the current directory, tweet.sh
will load it.Otherwise, the file ~/.tweet.client.key
will be used as the default key file.
Moreover, you can give those information via environment variables without a key file.
$ export MY_SCREEN_NAME=xxxxxxxxxxxxxxxxxxx
$ export MY_LANGUAGE=xx
$ export CONSUMER_KEY=xxxxxxxxxxxxxxxxxxx
$ export CONSUMER_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ export ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ export ACCESS_TOKEN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ ./tweet.sh post "Hello!"
This form will be useful to implement a bot program.
And, this script uses some external commands.You need to install them via package system on your environment: apt
, yum
or something.Required commands are:
curl
jq
nkf
openssl
$ ./tweet.sh [command] [...arguments]
Available commands are:
help
: shows usage of the tweet.sh
itself.fetch
(get
, show
): fetches a JSON string of a tweet.search
: searches tweets with queries.fetch-favorites
(fetch-fav
): fetches favorite tweets.fetch-tweets
(fetch-posts
): fetches tweets of a user.watch-mentions
(watch
): watches mentions, retweets, DMs, etc., and executes handlers for each event.type
: detects the type of the given input.body
: extracts the body of a tweet.owner
: extracts the owner of a tweet.showme
: reports the raw information of yourself.whoami
: reports the screen name of yourself.language
(lang
): reports the selected language of yourself.post
(tweet
, tw
): posts a new tweet.reply
: replies to an existing tweet.upload
: uploads a media file.delete
(del
, remove
, rm
): deletes a tweet.favorite
(fav
): marks a tweet as a favorite.unfavorite
(unfav
): removes favorited flag of a tweet.retweet
(rt
): retweets a tweet.unretweet
(unrt
): deletes the retweet of a tweet.follow
: follows a user.unfollow
: unfollows a user.fetch-direct-messages
(fetch-dm
, get-direct-messages
, get-dm
): fetches recent DMs.direct-message
(dm
): sends a DM.resolve
: resolves a shortened URL.resolve-all
: resolve all shortened URLs in the given input.If you want to handle DMs by the watch-mentions
command, you have to permit the app to access direct messages.
Detailed logs can be shown with the DEBUG
flag, like:
$ env DEBUG=1 ./tweet.sh search -q "Bash"
This script is mainly designed to be a client library to implement Twitter bot program, instead for daily human use.For most cases this script reports response JSONs of Twitter's APIs via the standard output.See descriptions of each JSON: a tweet, an event, and other responses also.
Some commands require URL of a tweet, and they accept shortened URLs like http://t.co/***
. Such URLs are automatically resolved as actual URLs like https://twitter.com/***/status/***
. The detectipn pattern for such shortened URLs is defined as URL_REDIRECTORS
in the script, and it must be updated for new services.
fetch
(get
, show
): fetches a JSON string of a tweetParameters
Standard output
Example
$ ./tweet.sh fetch 0123456789
$ ./tweet.sh fetch https://twitter.com/username/status/0123456789
$ ./tweet.sh get 0123456789
$ ./tweet.sh show 0123456789
search
: searches tweets with queries.Parameters
-q
: queries.If you specify no query, then you'll see sample tweets as results.-c
: maximum number of tweets to be responded. 10 by default. (optional)-s
: the id of the last tweet already known. (optional)If you specify this option, only tweets newer than the given tweet will be returned.-m
: the id of the tweet you are searching tweets older than it. (optional)If you specify this option, only tweets older than the given tweet will be returned.-t
: type of results. (optional)Possible values: recent
(default), popular
, or mixed
.-h
: command line to run for each search result. (optional)(It will receive tweets via the standard input.)-w
: start watching without handler. (optional)Standard output
Example
$ ./tweet.sh search -q "queries" -c 10
$ ./tweet.sh search -q "Bash OR Shell Script"
$ ./tweet.sh search -q "Bash OR Shell Script" -h 'echo "found!"; cat'
$ ./tweet.sh search -q "Bash OR Shell Script" -w |
while read -r tweet; do echo "found!: ${tweet}"; done
fetch-favorites
(fetch-fav
): fetches favorite tweets.Parameters
-u
: the screen name of the owner favorites to be fetched from. Yourself by default.-c
: maximum number of tweets to be fetched. 10 by default.-s
: the id of the last tweet already known. (optional)If you specify this option, only tweets newer than the given tweet will be returned.-m
: the id of the tweet you are searching tweets older than it. (optional)If you specify this option, only tweets older than the given tweet will be returned.Standard output
Example
$ ./tweet.sh fetch-favorites -c 20
$ ./tweet.sh fetch-fav -c 10 -s 0123456789
fetch-tweets
(fetch-posts
): fetches tweets of a user.Parameters
-u
: the screen name of the owner of tweets to be fetched from. Yourself by default.-c
: maximum number of tweets to be fetched. 10 by default.-s
: the id of the last tweet already known. (optional)If you specify this option, only tweets newer than the given tweet will be returned.-m
: the id of the tweet you are searching tweets older than it. (optional)If you specify this option, only tweets older than the given tweet will be returned.-a
: include replies.-r
: include retweets.-f
: returns full text of the tweet (not truncated) sends tweet_mode=extended
The json response changes the usual returned field from text
to full_text
.Standard output
Example
$ ./tweet.sh fetch-tweets -u screen_name -c 20
$ ./tweet.sh fetch-posts -u screen_name -c 10 -s 0123456789
Basically this command provides ability to get search result based on the given query.
If you want to observe new tweets matched to the query continuously, specify a callback command line as the handler via the -h
option.
$ ./tweet.sh search -q "queries" -h "echo 'FOUND'; cat"
In this case, only -q
and -h
options are available.The script doesn't exit automatically if you specify the -h
option.To stop the process, you need to send the SIGINT
signal via Ctrl-C or something.
Important note: you cannot use this feature together with watch-mentions
command. Only one streaming API is allowed for you at once.If you want to watch search results with mentions, use the -k
and -s
options of the watch-mentions
command.
watch-mentions
(watch
): watches mentions, retweets, DMs, etc., and executes handlers for each event.Parameters
-k
: comma-separated list of tracking keywords.-m
: command line to run for each reply or mention. (optional)(It will receive mention tweets via the standard input.)-r
: command line to run for each retweet. (optional)(It will receive retweet tweets via the standard input.)-q
: command line to run for each quotation. (optional)(It will receive quotation tweets via the standard input.)-f
: command line to run when a user follows you. (optional)(It will receive follow
event via the standard input.)-d
: command line to run when a DM is received. (optional)(It will receive quotation tweets via the standard input.)-s
: command line to run for each search result, matched to the keywords given via the -k
option. (optional)Standard output
Example 1: without handlers
$ ./tweet.sh watch-mentions -k "keyword1,keyword2,..." |
while read -r event; do echo "event: ${event}"; done
Example 2: with handlers
$ ./tweet.sh watch-mentions -k "keyword1,keyword2,..." \
-r "echo 'REPLY'; cat" \
-t "echo 'RT'; cat" \
-q "echo 'QT'; cat" \
-f "echo 'FOLLOWED'; cat" \
-d "echo 'DM'; cat" \
-s "echo 'SEARCH-RESULT'; cat"
This command provides ability to observe various events around you or any keyword.
In this case this script stays running.To stop the process, you need to send the SIGINT
signal via Ctrl-C or something.
Important note: you cannot use this feature together with search
command with a handler. Only one streaming API is allowed for you at once.If you want to watch search results with mentions, use the -k
and -s
options instead of the search
command.
type
: detects the type of the given input.Parameters
-k
: comma-separated list of keywords which are used for "search".Standard output
event-follow
: An event when you are followed.direct-message
: A direct message. It can be wrapped with a key direct_message
.quotation
: A commented RT.retweet
: An RT.mention
: A mention or reply.search-result
: A tweet which is matched to the given keywords.Example
$ echo "$tweet_json" | ./tweet.sh type -k keyword1,keyword2
This command provides ability to detect the type of each object returned from the user stream.For unknown type input, this returns an exit status 1
and reports nothing.
body
: extracts the body of a tweet.Parameters
Standard output
Example
$ ./tweet.sh body 0123456789
$ ./tweet.sh body https://twitter.com/username/status/0123456789
$ echo "$tweet_json" | ./tweet.sh body
owner
: extracts the owner of a tweet.Parameters
Standard output
Example
$ ./tweet.sh owner 0123456789
$ ./tweet.sh owner https://twitter.com/username/status/0123456789
$ echo "$tweet_json" | ./tweet.sh owner
showme
: reports the raw information of yourself.Parameters
Standard output
Example
$ ./tweet.sh showme
This will be useful if you want to get both informations whoami
and language
at once.
whoami
: reports the screen name of yourself.Parameters
Standard output
Example
$ ./tweet.sh whoami
username
Important note: the rate limit of the API used by this command is very low. If you want to call another language
command together, then you should use showme
command instead.
language
(lang
): reports the selected language of yourself.Parameters
Standard output
Example
$ ./tweet.sh language
en
$ ./tweet.sh lang
en
Important note: the rate limit of the API used by this command is very low. If you want to call another whoami
command together, then you should use showme
command instead.
post
(tweet
, tw
): posts a new tweet.Parameters
-m
: comma-separated list of uploaded media IDs. See also the upload
command.-l
: add location to tweet. (optional)Standard output
Example
$ ./tweet.sh post A tweet from command line
$ ./tweet.sh post 何らかのつぶやき
$ ./tweet.sh tweet @friend Good morning.
$ ./tweet.sh tw -m 123,456,789 My Photos!
$ ./tweet.sh post -l A tweet with location
$ cat body.txt | ./tweet.sh post
All rest arguments following to the command name are posted as a tweet.If you include a user's screen name manually in the body, it will become a mention (not a reply).
reply
: replies to an existing tweet.Parameters
-m
: comma-separated list of uploaded media IDs. See also the upload
command.Standard output
Example
$ ./tweet.sh reply 0123456789 @friend A regular reply
$ ./tweet.sh reply 0123456789 A silent reply
$ ./tweet.sh reply https://twitter.com/username/status/0123456789 @friend A regular reply
$ ./tweet.sh reply https://twitter.com/username/status/0123456789 A silent reply
$ ./tweet.sh reply 0123456789 -m 123,456,789 Photo reply
$ cat body.txt | ./tweet.sh reply 0123456789
Note that you have to include the user's screen name manually if it is needed.This command does not append it automatically.
upload
: uploads a file.Parameters
Standard output
Example
$ ./tweet.sh upload /path/to/file.png
delete
(del
, remove
, rm
): deletes a tweet.Parameters
Standard output
Example
$ ./tweet.sh delete 0123456789
$ ./tweet.sh del https://twitter.com/username/status/0123456789
$ ./tweet.sh remove 0123456789
$ ./tweet.sh rm https://twitter.com/username/status/0123456789
favorite
(fav
): marks a tweet as a favorite.Parameters
Standard output
Example
$ ./tweet.sh favorite 0123456789
$ ./tweet.sh favorite https://twitter.com/username/status/0123456789
$ ./tweet.sh fav 0123456789
$ ./tweet.sh fav https://twitter.com/username/status/0123456789
unfavorite
(unfav
): removes favorited flag of a tweet.Parameters
Standard output
Example
$ ./tweet.sh unfavorite 0123456789
$ ./tweet.sh unfavorite https://twitter.com/username/status/0123456789
$ ./tweet.sh unfav 0123456789
$ ./tweet.sh unfav https://twitter.com/username/status/0123456789
retweet
(rt
): retweets a tweet.Parameters
Standard output
Example
$ ./tweet.sh retweet 0123456789
$ ./tweet.sh retweet https://twitter.com/username/status/0123456789
$ ./tweet.sh rt 0123456789
$ ./tweet.sh rt https://twitter.com/username/status/0123456789
Note, you cannot add extra comment for the retweet.Instead, if you want to "quote" the tweet, then you just have to post
with the URL of the original tweet.
$ ./tweet.sh post Good news! https://twitter.com/username/status/0123456789
unretweet
(unrt
): deletes the retweet of a tweet.Parameters
Standard output
Example
$ ./tweet.sh unretweet 0123456789
$ ./tweet.sh unretweet https://twitter.com/username/status/0123456789
$ ./tweet.sh unrt 0123456789
$ ./tweet.sh unrt https://twitter.com/username/status/0123456789
follow
: follows a user.Parameters
Standard output
Example
$ ./tweet.sh follow @username
$ ./tweet.sh follow username
$ ./tweet.sh follow https://twitter.com/username/status/012345
unfollow
: unfollows a user.Parameters
Standard output
Example
$ ./tweet.sh unfollow @username
$ ./tweet.sh unfollow username
$ ./tweet.sh unfollow https://twitter.com/username/status/012345
#Operate direct messages
fetch-direct-messages
(fetch-dm
, get-direct-messages
, get-dm
): fetches recent DMs.Parameters
-c
: maximum number of messages to be fetched. 10 by default.Standard output
Example
$ ./tweet.sh fetch-direct-messages -c 20
$ ./tweet.sh get-direct-messages -c 20
direct-message
(dm
): sends a DM.Parameters
Standard output
Example
$ ./tweet.sh direct-message @friend Good morning.
$ ./tweet.sh direct-message friend Good morning.
$ ./tweet.sh dm @friend Good morning.
$ ./tweet.sh dm friend Good morning.
$ cat body.txt | ./tweet.sh direct-message @friend
#Misc.
resolve
: resolves a shortened URL.Parameters
Standard output
Example
$ ./tweet.sh resolve https://t.co/xxxx
resolve-all
: resolve all shortened URLs in the given input.Parameters
Standard output
Example
$ cat ./tweet-body.txt | ./tweet.sh resolve-all
编译spark:[thriftServer.sh属于测试阶段 hive-0.13.1] 说明: 目前已经发布了1.2版本此文至合适安装参考,不用自己编译了 vi sql/hive/pom.xml 支持读取parquet <dependency> <groupId>com.twitter</groupId> <artifactId>parquet-hiv
如何使用ja进行dom操作 John Althouse, Director of Threat Detection, Salesforce Salesforce威胁检测总监John Althouse Network threat detection is a moving target. Those of us in the threat detection corner of the secur