Examples on how to use twitter4s library.
Make sure to set up your consumer and access tokens -- see twitter4s README - Usage Section for more information.
Run the examples with sbt run
and choose the main to run.
- MyTopHashtags displays the top 10 most common hashtags in the home timeline (i.e.: the timeline of the authenticated user).
- SearchAndSaveTweets searches all the tweets matching some query and it saves the result as JSON in a file. In this example, the query used is
#scalax
and the generated file issrc/main/resources/tweets/scalax.json
. - SimpleStatistics loads tweets from a file, in this case
src/main/resources/tweets/scalax.json
, and it computes some simple statistics: top hashtags, top active users, top mentioned users, top retweets, top favorite tweets. - UserTopHashtags displays the top 10 most common hashtags in a user timeline. In this example, we use Martin Odersky's account.
- TrendingTopics displays the top 10 trending topics worldwide, and in a given location (by text and by geolocation).
- LastTweetInTimeline displays the last tweet in your timeline.
- FollowersRegisteredTheSameYear display for a user, the followers registered the same year.
- ShowTermsOfService display Twitter's terms of service.
- ShowPrivacyPolicy display Twitter's Privacy Policy.
- UserMentionStream receive stream of tweets mentioning yourself.
- StreamingWithLogging example on how to use logging in your twitter4s application.
- SampleStatusesHashtagPrinter filter tweets by hashtag and print all the hashtags for the filtered one.
- TweetTimelineStreamPrinter print the tweets in your timeline using stream.
If you have this exception javax.net.ssl.SSLHandshakeException: General SSLEngine problem
add the certificate of the twitter api to jre truststore.
echo -n | \
openssl s_client -connect api.twitter.com:443 </dev/null | \
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/twitter-api.crt && \
sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias twitterapi -file /tmp/twitter-api.crt
if the alias already exists, delete it before.
sudo keytool -delete -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -alias twitterapi
Spotted some bugs? Please, raise them in the twitter4s issue section.