首页 > 解决方案 > Cannot search for tweets using clojure twitter api twttr

问题描述

Using twttr and other Clojure twitter api libraries I have no issues with sending tweets or updates but I am unable to search or filter tweets for keywords.

I put the following command into the repl:

(ns twitter-search.core
    (:require [twttr.api :as api ]
                    [twttr.auth :refer [env->UserCredentials]]))

I then input the credentials, as following:

(def app-consumer-key "my key from dev.twitter " )

And the same for app-consumer-secret access and secret token; all seems fine there as when I type in repl app-consumer-key it returns the key all fine.

Then for credentials I do :

(def creds (env->UserCredentials))

I get users show to work fine by writing a small function:

(defn show-user [handle]
    (api/users-show creds :params {:screen_name handle}))

Then when I run (show-user "jack" ) in the repl I get all the json data one would expect so that is all fine and good.

The problem I am having is searching for tweets. When I put the following into the repl:

(api/search-tweets creds :params {:q "football"})

It does nothing, other than go from the current namespace

twitter-search.core=>

To

#_=> 

If you could point out where I'm going wrong or send an example of how to search tweets containing certain words I would be most grateful.

I even did quite long tail searches and posted the same term from another twitter account to see if I could prompt the program to detect the tweet but nothing happened.

(ns twitter-search.core
    (:require [twttr.api :as api ]
                    [twttr.auth :refer [env->UserCredentials]]))


(def app-consumer-key "my key from dev.twitter " )

(def creds (env->UserCredentials))

(defn show-user [handle]
    (api/users-show creds :params {:screen_name handle}))



;; The problem I am having is searching for tweets. 
;; When I put the following into the repl:

(api/search-tweets creds :params {:q "football"})

;; It does nothing, other than go from the current namespace 

twitter-search.core=>

;; To 

#_=> 

I just want to be able to know how to use the twttr clojure library to filter out tweets based of certain keywords within their tweets. I know this probably seems a silly question, however, I am new to Clojure, I have not fouind a working example anywhere and have tried many times to get it to work.

标签: apitwitterclojure

解决方案


我觉得很傻:-(

我能够修复它,不确定是什么导致了问题;我通常会尝试多次解决问题,并且通常会在发布之前自己回答。

无论如何,以下函数返回了我正在寻找的内容:

(defn keyword-return [keyword]
  (api/search-tweets creds :params {:q keyword})) 

推荐阅读