drone29a / clojure-twitter Goto Github PK
View Code? Open in Web Editor NEWClojure client for Twitter API
License: BSD 2-Clause "Simplified" License
Clojure client for Twitter API
License: BSD 2-Clause "Simplified" License
Hi,
Great lib, works fine locally. But when deployed on GAE, https doesn't works (javax.net.ssl.HttpsURLConnection is a restricted class).
So I swiched to regular http:
(twitter/with-oauth
instead of :
(twitter/with-https
(twitter/with-oauth
In fact even if I only :require the twitter lib without using it, it breaks.
Here's the stacktrace: https://gist.github.com/973086
A solution could be to use HttpConnection instead of HttpsConnection, the former is on the GAE whitelist.
Any hints ?
thx
Denis
Is it possible to make multiple requests to the Twitter APIs using a single OAuth token?
Something along the lines of
(defn make-friends [ids]
:description "ids is a list of twitter ids"
(twitter/with-oauth oauth-consumer access-token access-token-secret (map twitter/create-friendship-to-id ids))
)
Thanks
Robert
I ran this code in a SLIME REPL:
(require 'twitter)
(twitter/show-user-by-name "ieure")
This printed the warning:
Aug 13, 2011 2:08:26 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Invalid cookie header: "Set-Cookie: guest_id=v1%3A1313269705954407; domain=.twitter.com; path=/; expires=Tue, 13 Aug 2013 09:08:25 GMT". Unable to parse expires attribute: Tue, 13 Aug 2013 09:08:25 GMT
Which makes SLIME very unhappy. It would be nice if these were silenced by default.
Trying to update your status with stuff like this: ⟹
results in stuff like this:
twitter.proxy$java.lang.Exception$0: [401] Incorrect signature. [/1/statuses/upd
ate.json]
at twitter.proxy$java.lang.Exception$0.fillInStackTrace (:-1)
java.lang.Throwable.<init> (Throwable.java:213)
java.lang.Exception.<init> (Exception.java:58)
twitter.proxy$java.lang.Exception$0.<init> (:-1)
twitter$status_handler.invoke (twitter.clj:618)
clojure.core$comp$fn__3642.invoke (core.clj:1946)
twitter$update_status.doInvoke (twitter.clj:146)
clojure.lang.RestFn.invoke (RestFn.java:411)
sexpbot.twitter$eval10997$fn__10999.invoke (twitter.clj:98)
clojure.lang.MultiFn.invoke (MultiFn.java:167)
sexpbot.plugins.haskell$heval_cmd$fn__12787.invoke (haskell.clj:38)
sexpbot.registry$try_handle$fn__10866$fn__10869.invoke (registry.clj:101)
clojure.lang.AFn.call (AFn.java:18)
java.util.concurrent.FutureTask$Sync.innerRun (FutureTask.java:334)
java.util.concurrent.FutureTask.run (FutureTask.java:166)
java.lang.Thread.run (Thread.java:636)
Maybe clojure-twitter could handle this sort of thing directly.
The post of DM without URL encoding,
(twitter/with-oauth
oauth-consumer
oauth-access-token
oauth-access-token-secret
(twitter/send-direct-message-to-id my-id "こんにちは"))
it fails with the following error.
2011/10/30 2:22:11 org.apache.http.impl.client.DefaultRequestDirector handleResponse
Warning: Authentication error: Unable to respond to any of these challenges: {oauth=WWW-Authenticate: OAuth realm="http://api.twitter.com"}
twitter.proxy$java.lang.Exception$0: [401] Could not authenticate with OAuth.. [/1/direct_messages/new.json] (NO_SOURCE_FILE:0)
But when the string is apparently encoded,
(twitter/with-oauth
oauth-consumer
oauth-access-token
oauth-access-token-secret
(twitter/send-direct-message-to-id my-id (java.net.URLEncoder/encode "こんにちは" "UTF-8")))
it succeeds to post.
I saw the packet of POST request, and the text was "%3F%3F%3F%3F%3F%3F"... (this is a result of another UTF-8 string).
I suspect this is because the UTF-8 string is not properly converted in your library.
=> (require 'twitter)
Warning: print-pretty not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-pretty or change the name. (clojure/contrib/pprint/pprint_base.clj:29)
Warning: print-pprint-dispatch not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-pprint-dispatch or change the name. (clojure/contrib/pprint/pprint_base.clj:33)
Warning: print-pprint-dispatch not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-pprint-dispatch or change the name. (clojure/contrib/pprint/pprint_base.clj:33)
Warning: print-right-margin not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-right-margin or change the name. (clojure/contrib/pprint/pprint_base.clj:38)
Warning: print-miser-width not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-miser-width or change the name. (clojure/contrib/pprint/pprint_base.clj:44)
Warning: print-lines not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-lines or change the name. (clojure/contrib/pprint/pprint_base.clj:51)
Warning: print-circle not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-circle or change the name. (clojure/contrib/pprint/pprint_base.clj:56)
Warning: print-shared not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-shared or change the name. (clojure/contrib/pprint/pprint_base.clj:61)
Warning: print-suppress-namespaces not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-suppress-namespaces or change the name. (clojure/contrib/pprint/pprint_base.clj:65)
Warning: print-radix not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-radix or change the name. (clojure/contrib/pprint/pprint_base.clj:72)
Warning: print-base not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic print-base or change the name. (clojure/contrib/pprint/pprint_base.clj:78)
Warning: current-level not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic current-level or change the name. (clojure/contrib/pprint/pprint_base.clj:89)
Warning: current-length not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic current-length or change the name. (clojure/contrib/pprint/pprint_base.clj:91)
Warning: format-str not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic format-str or change the name. (clojure/contrib/pprint/cl_format.clj:64)
CompilerException java.lang.IllegalStateException: Can't dynamically bind non-dynamic var: clojure.contrib.pprint/format-str, compiling:(dispatch.clj:90)
I'm getting 410 responses because the library is making requests to this end point:
api.twitter.com/1/statuses/home_timeline.json
when it needs to be
api.twitter.com/1.1/statuses/home_timeline.json
now.
I'm not sure if you're still taking pull requests for this project? If so I can update the URL scheme pretty easily and send it to you?
Cheers, Jason.
A function that takes a URL path and arguments and makes a HTTP request to the Twitter API should be used to permit the user to select the HTTP lib and wrap fetch calls as appropriate.
It doesn't look like oauth is being included.
(ns hello.core)
(defn -main
[]
(require 'twitter
'[oauth.client :as oauth])
;; Make a OAuth consumer
(def oauth-consumer (oauth/make-consumer <key>
<secret>
"https://api.twitter.com/oauth/request_token"
"https://api.twitter.com/oauth/access_token"
"https://api.twitter.com/oauth/authorize"
:hmac-sha1))
(def oauth-access-token "1528170666-Ex4iQ0lz6b1KUWrbHWU9FoFtuP20lFpXMeZNRXY")
(def oauth-access-token-secret "xzydqNtuvg2e2UXKe53YA0RZzJ20o4yZF8INIGswmRn9B")
;; Post to twitter
(twitter/with-oauth oauth-consumer
oauth-access-token
oauth-access-token-secret
(twitter/update-status "posting from #clojure with #oauth")))
I've been using clojure-twitter and clj-oauth to add some twitter support to sexpbot (on the protocols branch). It appears that every time it makes a request, something like this prints:
Nov 24, 2010 10:16:04 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Invalid cookie header: "Set-Cookie: guest_id=129065856351069239; path=/; expires=Sat, 25 Dec 2010 04:16:03 GMT". Unable to parse expires attribute: Sat, 25 Dec 2010 04:16:03 GMT
Is there any way to suppress these warnings? Or, better yet, am I doing something to cause these warnings?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.