-
-
Save halcat0x15a/6914155 to your computer and use it in GitHub Desktop.
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
(defproject update-tweets "0.1.0-SNAPSHOT" | |
:dependencies [[org.clojure/clojure "1.5.1"] | |
[org.twitter4j/twitter4j-core "3.0.4"]] | |
:jvm-opts ["-Dtwitter4j.oauth.consumerKey=" | |
"-Dtwitter4j.oauth.consumerSecret="]) |
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) | |
request-token (.getOAuthRequestToken twitter)] | |
(println "Got request token.") | |
(println "Reuest token: " (.getToken request-token)) | |
(println "Reuest token secret: " (.getTokenSecret request-token)) | |
(with-local-vars [access-token nil] | |
(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 (read-line)] | |
(println "pin <- " pin) | |
(var-set access-token (if (pos? (count pin)) | |
(.getOAuthAccessToken twitter request-token pin) | |
;; else | |
(.getOAuthAccessToken twitter request-token))))) | |
(println "Got access token.") | |
(println "Access token: " (.getToken @access-token)) | |
(println "Access token secret: " (.getTokenSecret @access-token)) | |
(let [status (.updateStatus twitter "Hello, Twitter4j!!")] | |
(println "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