adamwynne / twitter-api

Async io interface to all the twitter APIs
372 stars 64 forks source link

"account/update-profile-banner" Throwing Exception #40

Open ghost opened 10 years ago

ghost commented 10 years ago

Hi Adam,

I'm trying to use account-update-profile-banner: (account-update-profile-banner :oauth-creds my-twitter-user-creds :params {:banner base64-banner}) where base64-banner is a base64 encoded JPEG file.

I have the pretty same code running for account-update-profile-image which runs without any difficulties. (Parameter is called differently. "image" instead of "banner".)

The banner image is updated actually on Twitter but above mentioned function call results in following exception: No matching clause:

In case you want to try out the function for yourself you might want to use following helper function for encoding a JPEG file:

(ns twitter-me.core
  (:require 
          [me.raynes.fs :as fs]
          [clojure.data.codec.base64 :as b64]
          [clojure.java.io :as io]))

(defn encode-jpeg-file [file-name]
  (with-open [in (io/input-stream (io/file file-name))]
    (let [buf (byte-array (fs/size file-name))
          n (.read in buf)]
      (apply str (map char (b64/encode buf))))))

I assume it has something to do with the callback handling but I couldn't find it in the code. I assume a cond is causing the issue.

Kind regards, Hans-J.

ghost commented 10 years ago

Dear Adam,

here is the stacktrace:

IllegalArgumentException No matching clause: 
    clojure.data.json/read-json (json_compat_0_1.clj:23)
    clojure.data.json/read-json (json_compat_0_1.clj:18)
    twitter.callbacks.handlers/response-return-everything (handlers.clj:36)
    twitter.callbacks.handlers/handle-response (handlers.clj:111)
    twitter.request/get-response-transform/fn--8788 (request.clj:29)
    twitter.request/execute-request-callbacks (request.clj:45)
    twitter.core/http-request (core.clj:103)
    twitter.api.restful/account-update-profile-banner (restful.clj:36)
...

Is there anything else I could do to see what's going on?

Kind regards, Hans-J.

ghost commented 10 years ago

Dear Adam,

this is what I get when I set :callbacks (SyncSingleCallback. identity identity identity)

 {:id req-id__10666,
 :url "https://api.twitter.com/1.1/account/update_profile_banner.json",
 :raw-url
 "https://api.twitter.com/1.1/account/update_profile_banner.json",
 :status
 #<Promise@58d181d3: 
   {:code 201,
    :msg "Created",
    :protocol "HTTP/1.1",
    :major 1,
    :minor 1}>,
 :headers
 #<Promise@56b5dd08: 
   {:cache-control
    "no-cache, no-store, must-revalidate, pre-check=0, post-check=0",
    :content-length "0",
    :content-type "text/html;charset=utf-8",
    :date "Sat, 01 Feb 2014 06:29:37 GMT",
    :expires "Tue, 31 Mar 1981 05:00:00 GMT",
    :last-modified "Sat, 01 Feb 2014 06:29:37 GMT",
    :pragma "no-cache",
    :server "tfe",
    :set-cookie
    ["lang=en"
     "guest_id=v1%3A139123617713821120; Domain=.twitter.com; Path=/; Expires=Mon, 01-Feb-2016 06:29:37 UTC"],
    :status "201 Created",
    :strict-transport-security "max-age=631138519",
    :x-access-level "read-write-directmessages",
    :x-frame-options "SAMEORIGIN",
    :x-transaction "6008f85fe9f84a60",
    :x-xss-protection "1; mode=block"}>,
 :body #<Promise@2560c024: nil>,
 :done #<Promise@72e68ea7: true>,
 :error #<Promise@7e9fb0df: :not-delivered>}

So status is OK (201) and as I said before Twitter updated the banner image.

Best regards, Hans-J.

adamwynne commented 10 years ago

check out the example for posting a picture status:

(statuses-update-with-media :oauth-creds creds :body [(file-body-part "/pics/test.jpg") (status-body-part "testing")])

On Fri, Jan 31, 2014 at 8:47 PM, schmidh notifications@github.com wrote:

Hi Adam,

I'm trying to use account-update-profile-banner: (account-update-profile-banner :oauth-creds my-twitter-user-creds :params {:banner base64-banner}) where base64-banner is a base64 encoded JPEG file.

I have the pretty same code running for account-update-profile-imagewhich runs without any difficulties. (Parameter is called differently. "image" instead of "banner".)

The banner image is updated actually on Twitter but above mentioned function call results in following exception: No matching clause:

In case you want to try out the function for yourself you might want to use following helper function for encoding a JPEG file:

(ns twitter-me.core (:require [me.raynes.fs :as fs] [clojure.data.codec.base64 :as b64] [clojure.java.io :as io])) (defn encode-jpeg-file [file-name](with-open [in %28io/input-stream %28io/file file-name%29%29] %28let [buf %28byte-array %28fs/size file-name%29%29 n %28.read in buf%29] %28apply str %28map char %28b64/encode buf%29%29%29%29))

I assume it has something to do with the callback handling but I couldn't find it in the code. I assume a cond is causing the issue.

Kind regards, Hans-J.

Reply to this email directly or view it on GitHubhttps://github.com/adamwynne/twitter-api/issues/40 .

ghost commented 10 years ago

Hi Adam,

thanks a lot for your quick response.

Here what I tried. When I use

(account-update-profile-banner 
:oauth-creds twitter-user-creds 
:body [(file-body-part my-jpeg-banner-file) (status-body-part "testing")])))

I get exception Exception Twitter responded to request with error 211: Image error: banner param not provided.

Adding the :banner parameter

(account-update-profile-banner 
:oauth-creds twitter-user-creds 
:params {:banner base64-banner} 
:body [(file-body-part my-jpeg-banner-file) (status-body-part "testing")])))

results again in Exception IllegalArgumentException No matching clause: clojure.data.json/read-json (json_compat_0_1.clj:23)

ghost commented 10 years ago

Hi Andi,

just realized by looking at the twitter-api source code that these attempts can't work. file-body-part adds media[] which is used by statuses/update_with_media. Same goes for status-body-part which is also centered around statuses/update_with_media.

I don't know what to do now. I'm pretty clueless. Should I use a more generic function like add-body?

Kind regards, Hans-J.