adamwynne / twitter-api

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

Support for media upload #66

Closed danielsz closed 6 years ago

danielsz commented 8 years ago

Hi,

I can't find support for media upload.

https://dev.twitter.com/rest/reference/post/media/upload

Would you consider a PR?

Thanks!

Daniel

prateekbhatt commented 8 years ago

Any updates on this ?

adamwynne commented 8 years ago

All pr's welcome

On Sunday, 15 November 2015, Daniel Szmulewicz notifications@github.com wrote:

Hi,

I can't find support for media upload.

https://dev.twitter.com/rest/reference/post/media/upload

Would you consider a PR?

Thanks!

Daniel

— Reply to this email directly or view it on GitHub https://github.com/adamwynne/twitter-api/issues/66.

wiseman commented 6 years ago

Especially now that update_with_media has been deprecated.

wiseman commented 6 years ago

Something like this almost works:

(def ^:dynamic *rest-upload-api-1_1* (twitter.api/make-api-context "https" "upload.twitter.com" "1.1"))

(twitter/def-twitter-restful-method :post "media/upload"
  :api *rest-upload-api-1_1*
  :headers {:content-type "multipart/form-data"})

It works for the simple form of media/upload, but unfortunately that only supports plain images, not videos or gifs. To use those you need to use the chunked media upload API, and the problem I ran into there is that when I send the APPEND command I get the following exception:

1. Unhandled java.lang.IllegalArgumentException
   No matching clause:

       json_compat_0_1.clj:   23  clojure.data.json/read-json
       json_compat_0_1.clj:   10  clojure.data.json/read-json
       json_compat_0_1.clj:   18  clojure.data.json/read-json
       json_compat_0_1.clj:   10  clojure.data.json/read-json
              handlers.clj:   29  twitter.callbacks.handlers/response-return-everything
              handlers.clj:   23  twitter.callbacks.handlers/response-return-everything
               RestFn.java:  410  clojure.lang.RestFn/invoke
              handlers.clj:   91  twitter.callbacks.handlers/handle-response
              handlers.clj:   81  twitter.callbacks.handlers/handle-response
               RestFn.java:  464  clojure.lang.RestFn/invoke
               request.clj:   22  twitter.request/get-response-transform/fn
               request.clj:   35  twitter.request/execute-request-callbacks
               request.clj:   27  twitter.request/execute-request-callbacks
                  core.clj:   77  twitter.core/http-request
                  core.clj:   63  twitter.core/http-request

I'm wondering if the issue is that media/upload APPEND doesn't return a body.

wiseman commented 6 years ago

(I've looked at twttr but that doesn't support media/upload either.)

wiseman commented 6 years ago

I've submitted a pull request that adds support for media/upload.

(@chbrown, I looked at adding support to twttr, but it seemed that maybe aleph didn't have great support for multipart/form-data.)

chbrown commented 6 years ago

Cool, thanks. Works great! Touched up a couple things in 29efaf1. Want to play around with it a little bit more, but I can cut a v1.8.1 or v1.9.0 release soon.

Yeah, at the moment twttr isn't much more than a refactor of twitter-api. I've got some changes sitting in my working directory, and now that I've got a reference point for consuming media/upload, I'll see what it takes to translate that to aleph.