geduldig / TwitterAPI

Minimal python wrapper for Twitter's REST and Streaming APIs
935 stars 263 forks source link

Can't perform GET of the media/upload endpoint #76

Closed bcattle closed 7 years ago

bcattle commented 8 years ago

Hey, due to Twitter increasing the allowed video length to 140 secs, there's a new asyncronous processing step that may or may not take place when you upload a video. You can read about it here, see under FINALIZE -> "Async finalize which requires subsequent STATUS call".

Basically, you perform the chunked upload as before, then if the POST media/upload response contains the field processing_info, you need to poll to determine when the media is done processing, before you can use the media_id in a tweet.

This polling is accomplished by doing a GET of the media/upload endpoint. This GET operation isn't currently permitted by the TwitterAPI library. The library hard-codes the POST HTTP method for the media/upload endpoint.

I needed to get this working quickly, so I forked the library and added a method_override argument to the request() function to allow this. You can see it here.

I'm not sure if this is the best way to solve this problem. If it is I can create a PR. Thanks.

geduldig commented 8 years ago

Are doing something like this example? https://github.com/geduldig/TwitterAPI/blob/master/examples/upload_video.py

What version of TwitterAPI are you using?

bcattle commented 8 years ago

Yeah I'm doing exactly what's in the example. The call to 'FINALIZE' on line 53, can now return a response like the following, which indicates that an asynchronous processing step is to be performed:

"processing_info": {
    "state": "pending",
    "check_after_secs": 5 // check after 5 seconds for update using STATUS command
}

If you get this response, you need to make subsequent GET calls to 'media/upload' until the "state" becomes "failed" or "succeeded".

See here for more information, down under "STATUS".

I'm using the latest version of master.

geduldig commented 8 years ago

Okay, I had some more time to look at this, and I see what you are talking about. Your patch looks good, but I want to first see if I prefer any alternatives. Thank you for pointing this out.

geduldig commented 8 years ago

I like your solution over other alternatives. If you make a pull request I'll add it. Thanks again!