Search code examples
twitterclojureslf4jleiningennumberformatexception

twitter-api: user token raises java.lang.NumberFormatException


project.clj

(defproject twit-api-learn "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [ring/ring-core "1.2.2"]
                 [ring/ring-jetty-adapter "1.2.2"]
                 [clj-http "0.9.2"]
                 [twitter-api "0.7.5"]])

core.clj

(ns twit-api-learn.core
 (:use
   [twitter.oauth]
   [twitter.callbacks]
   [twitter.callbacks.handlers]
   [twitter.api.restful])
  (:import
   (twitter.callbacks.protocols SyncSingleCallback)))

(def my-creds (make-oauth-creds 0123456
                                0123456
                                012345-012345
                                0123456))

Error:

user=> (require 'twit-api-learn.core)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

CompilerException java.lang.NumberFormatException: Invalid number: 012345-012345, compiling:(twit_api_learn/core.clj:10:160) 

So the error is being raised on the user token - the (fake) number 012345-012345. All of the "012345"s actually have their correct counterpart in core.clj.

Did I mention I'm new? :)


Solution

  • 012345-012345 is indeed not a number, but the Clojure reader would try to treat it as one (before failing).

    I don't see from the source of twitter-api what type that arg should have, but try making each argument a String, ie. "012345-012345", "0123456" ...