Skip to content

Instantly share code, notes, and snippets.

@jackrusher
Created December 24, 2012 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackrusher/4370149 to your computer and use it in GitHub Desktop.
Save jackrusher/4370149 to your computer and use it in GitHub Desktop.
Grab the last N tweets for user, where N is decided by Twitter's API limit.
(defn fetch-tweets
[user]
(loop [max-id nil accum []]
(let [fetch-str (str "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&screen_name=" user "&count=1500" (when max-id (str "&max_id=" max-id)))
chunk (try (json/read-str (slurp fetch-str)) (catch Exception e))]
(if (or (nil? chunk) (< 200 (count chunk)))
(conj accum chunk)
(recur ((last chunk) "id") (conj accum chunk))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment