Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add support for the new metadata endpoint #67

Closed
ghost opened this issue Apr 2, 2016 · 8 comments
Closed

Please add support for the new metadata endpoint #67

ghost opened this issue Apr 2, 2016 · 8 comments

Comments

@ghost
Copy link

ghost commented Apr 2, 2016

Using the media/metadata/create endpoint as described in https://dev.twitter.com/rest/reference/post/media/metadata/create requires adding a "Content-Type: application/json" header, but currently twurl (or the Ruby OAuth library it uses) overwrites this with "Content-Type: application/x-www-form-urlencoded", resulting in a "401 Authorization Required" and "32 Could not authenticate you." response from the API.

Minimal solution would be to not overwrite such a header, better would be to support JSON content for POSTs.

@BooDoo
Copy link

BooDoo commented Apr 2, 2016

twurl 0.9.3 with modern (2.3.0) and legacy (1.9.3p551) ruby handles -A parameter correctly in my testing.

Anyone else who can reproduce? This new endpoint is an important feature but it's also an odd duck implementation compared to other existing REST 1.1 ones.

With 1.9.3p551:

$ rvm 1.9.3 do ruby $twurl_path/bin/twurl -t -A "Content-Type: application/json" -H upload.twitter.com "/1.1/media/metadata/create.json" -d "{\"media_id\": 716330049918648320, \"alt_text\":{\"text\": \"some label here\"} }"

USING RUBY VERSION: 1.9.3
opening connection to upload.twitter.com...
opened
<- "POST /1.1/media/metadata/create.json HTTP/1.1\r\nContent-Type: application/json\r\nAccept: */*\r\nUser-Agent: OAuth gem v0.5.1\r\nAuthorization: …\r\nConnection: close\r\nHost: upload.twitter.com\r\nContent-Length: 73\r\n\r\n"
<- "{\"media_id\": 716330049918648320, \"alt_text\":{\"text\": \"some label here\"} }"
-> "HTTP/1.1 200 OK\r\n"
…
-> "status: 200 OK\r\n"
…
-> "\r\n"
reading 0 bytes...
-> ""
read 0 bytes
Conn close

With 2.3.0:

$ rvm 2.3.0 do ruby $twurl_path/bin/twurl -t -A "Content-Type: application/json" -H upload.twitter.com "/1.1/media/metadata/create.json" -d "{\"media_id\": 716330049918648320, \"alt_text\":{\"text\": \"some label here\"} }"

USING RUBY VERSION: 2.3.0
opening connection to upload.twitter.com:443...
opened
starting SSL for upload.twitter.com:443...
SSL established
<- "POST /1.1/media/metadata/create.json HTTP/1.1\r\nContent-Type: application/json\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: OAuth gem v0.5.1\r\nAuthorization: …\r\nConnection: close\r\nHost: upload.twitter.com\r\nContent-Length: 73\r\n\r\n"<- "{\"media_id\": 716330049918648320, \"alt_text\":{\"text\": \"some label here\"} }"
-> "HTTP/1.1 200 OK\r\n"
…
-> "status: 200 OK\r\n"
…
-> "\r\n"
reading 0 bytes...
-> ""
read 0 bytes
Conn close

@ghost
Copy link
Author

ghost commented Apr 2, 2016

I see "User-Agent: OAuth gem v0.5.1" in both of your examples. Over here I get "User-Agent: OAuth gem v0.4.7". I just checked, and even the latest Ubuntu only has v0.4.7 of that package :/

@BooDoo
Copy link

BooDoo commented Apr 2, 2016

Forced downgrade to match patch level and OAuth gem, same result.

Can you share your command+output to see if anything stands out?

$ rvm 1.9.3-p484 do ruby $twurl_path/bin/twurl -t -A "Content-Type: application/json" \
-H upload.twitter.com "/1.1/media/metadata/create.json" \
-d "{\"media_id\": 716330049918648320, \"alt_text\":{\"text\": \"some label here\"} }"

USING RUBY VERSION: 1.9.3-p484
opening connection to upload.twitter.com...
opened
<- "POST /1.1/media/metadata/create.json HTTP/1.1\r\nContent-Type: application/json\r\nAccept: */*\r\nUser-Agent: OAuth gem v0.4.7\r\nAuthorization: …\r\nConnection: close\r\nHost: upload.twitter.com\r\nContent-Length: 73\r\n\r\n"
<- "{\"media_id\": 716330049918648320, \"alt_text\":{\"text\": \"some label here\"} }"
-> "HTTP/1.1 200 OK\r\n"
…
-> "status: 200 OK\r\n"
…
-> "\r\n"
reading 0 bytes...
-> ""
read 0 bytes
Conn close

@ghost
Copy link
Author

ghost commented Apr 2, 2016

Here's what I got:

~/scriptfun/twurl/bin/twurl -t -A "Content-Type: application/json" -H upload.twitter.com "/1.1/media/metadata/create.json" -d "{\"media_id\": 716361330786050048, \"alt_text\":{\"text\": \"some label here\"} }"
opening connection to upload.twitter.com...
opened
<- "POST /1.1/media/metadata/create.json HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept: */*\r\nUser-Agent: OAuth gem v0.4.7\r\nAuthorization: OAuth ..., oauth_version=\"1.0\"\r\nConnection: close\r\nHost: upload.twitter.com\r\nContent-Length: 105\r\n\r\n"
<- "%7B%22media_id%22%3A+716361330786050048%2C+%22alt_text%22%3A%7B%22text%22%3A+%22some+label+here%22%7D+%7D"
-> "HTTP/1.1 401 Authorization Required\r\n"
-> "connection: close\r\n"
-> "content-length: 64\r\n"
-> "content-type: application/json; charset=utf-8\r\n"
-> "date: Sat, 02 Apr 2016 20:27:15 GMT\r\n"
-> "server: tsa_b\r\n"
-> "set-cookie: guest_id=v1%3A145962883500649331; Domain=.twitter.com; Path=/; Expires=Mon, 02-Apr-2018 20:27:15 UTC\r\n"
-> "strict-transport-security: max-age=631138519\r\n"
-> "vary: Origin\r\n"
-> "x-connection-hash: 9287491a8012cd36b7d9e3bd5ceab674\r\n"
-> "x-frame-options: SAMEORIGIN\r\n"
-> "x-response-time: 9\r\n"
-> "x-tsa-request-body-time: 149\r\n"
-> "x-xss-protection: 1; mode=block\r\n"
-> "\r\n"
reading 64 bytes...
-> ""
-> "{\"errors\":[{\"code\":32,\"message\":\"Could not authenticate you.\"}]}"
{"errors":[{"code":32,"message":"Could not authenticate you."}]}read 64 bytes
Conn close

@ghost
Copy link
Author

ghost commented Apr 2, 2016

Hoh.. I think I've found the problem. I thought I had my twurl installation matched to the latest version, but turns out it was still v0.9.2.
Installed v0.9.3 (and reapplied my hack to read the config from ./twurlrc instead of ~/.twurlrc) and.. oy, that looks more like it should 😄

@BooDoo
Copy link

BooDoo commented Apr 2, 2016

OK, I think this is because you're using twurl gem version 0.9.2
This appears to be behavior fixed by #60 which is in the latest, but not in 0.9.2

EDIT: jinx

@ghost
Copy link
Author

ghost commented Apr 2, 2016

Yep, just tried tweeting, and there's alt text now \o/

@ghost
Copy link
Author

ghost commented Apr 2, 2016

Well, I guess that solves the issue. Might still want to consider adding something to not need the Content-Type: header, but at least things work for now.

@ghost ghost closed this as completed Apr 2, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant