Last active
December 25, 2015 03:59
-
-
Save noqisofon/6913711 to your computer and use it in GitHub Desktop.
clojure で twitter4j を使ってみた。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns org.example.twitter4j.tweets | |
(:import (twitter4j Status Twitter TwitterException TwitterFactory) | |
(twitter4j.auth AccessToken RequestToken) | |
(java.io BufferedReader IOException InputStreamReader))) | |
(let [twitter (TwitterFactory/getSingleton)] | |
(let [request-token (.getOAuthRequestToken twitter) | |
access-token (atom nil)] | |
(println "Got request token.") | |
(println (str "Reuest token: " (str (.getToken request-token)))) | |
(println (str "Reuest token secret: " (str (.getTokenSecret request-token)))) | |
(while (nil? @access-token) | |
(println "Open the following URL and grant access to your account:") | |
(println (.getAuthorizationURL request-token)) | |
(print "Enter the PIN(if available) and hit enter after you granted access.[PIN]:") | |
(flush) | |
(let [pin (readLine)] | |
(reset! access-token (if (> (.length pin) 0) | |
(.getOAuthAccessToken twitter request-token pin) | |
(.getOAuthAccessToken twitter request-token))))) | |
(println "Got access token.") | |
(println (str "Access token: " (.getToken @access-token))) | |
(println (str "Access token secret: " (.getTokenSecret @access-token))) | |
(let [status (.updateStatus twitter "Hello, Twitter4j!!")] | |
(println (str "Successfully updated the status to [" (.getText status) "]."))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment