twitter.lisp 987 B

12345678910111213141516171819202122232425262728
  1. (in-package #:chatikbot)
  2. (defsetting *twitter-access-token* nil "OAuth access token")
  3. (defparameter *timeline-url* "https://api.twitter.com/1.1/statuses/user_timeline.json")
  4. (defun get-tweets (user-id &key since-id (count 5))
  5. (loop for status in
  6. (yason:parse
  7. (babel:octets-to-string
  8. (cl-oauth:access-protected-resource
  9. (format nil "~A?~A"
  10. *timeline-url*
  11. (cl-oauth::alist->query-string
  12. (remove-if
  13. (complement #'cdr)
  14. (list
  15. (cons "user_id" user-id)
  16. (cons "count" count)
  17. (cons "since_id" since-id)
  18. (cons "trim_user" 1)
  19. (cons "exclude_replies" 1)))
  20. :include-leading-ampersand nil))
  21. *twitter-access-token*))
  22. :object-as :alist)
  23. collect (cons
  24. (aget "id" status)
  25. (aget "text" status))))