I can issue this command fine:

twurl -d 'status=Test tweet using the POST statuses/update endpoint' /1.1/statuses/update.json

It spits out a JSON return and a tweet is posted.

This one gives me no response at all:

twurl -X POST -H upload.twitter.com /1.1/media/upload.json -f /folder/photo.jpg -F media

I tried with quotes, without, in all combinations. Nothing happens. The picture on that folder has the appropriate permissions.

This was working until a week ago. I checked to see what was happening and something was broke on twurl - I re-installed it using “gem install twurl” and the program itself was fixed but the behaviour is not back to what it was.

Any ideas? I am running Ubuntu 22.04.

Thank you.

Does this work?

twurl -X POST -H "upload.twitter.com" "/1.1/media/upload.json" -f "/folder/photo.jpg" -F media

?

Nope, quoting things around doesn’t change the outcome unfortunately.

add -t to the command to get verbose output, and see what it gives you - if you get a “Forbidden” error it’s most likely you’re not using keys with Read & Write Access. After setting Read & Write permissions you must reset the access token. Is your app write restricted on the developer dashboard?

1 Like

Thanks for this tip, I was able to see a bit better what’s going on. I am getting 404 not found:

opening connection to api.twitter.com:443...
opened
starting SSL for api.twitter.com:443...
SSL established, protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384
<- "GET /1.1/media/upload.json HTTP/1.1\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: twurl version: 0.9.6 platform: ruby 3.0.2 (x86_64-linux-gnu)\r\nContent-Type: multipart/form-data, boundary=\"00Twurl263435600159687378lruwT99\"\r\nAuthorization: OAuth oauth_consumer_key=\"xxxxxxxxxxxxx\", oauth_nonce=\"xxxxxxxxxxxxxx\", oauth_signature=\"xxxxxxxxxxxxxxxxxxxxxxxxx\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1662232067\", oauth_token=\"xxxxxxxxxxxxx-xxxxxxxxxxxxxxxx\", oauth_version=\"1.0\"\r\nConnection: close\r\nHost: api.twitter.com\r\nContent-Length: 76679\r\n\r\n"
<- "--00Twurl263435600159687378lruwT99\r\nContent-Disposition: form-data; name=\"media\"; filename=\"photo.jpg\"\r\nContent-Type: application/octet-stream\r\n\r\n\xFF\xD8\xFF\xE1\x13\xEAExif\x00\x00MM\x00*\x00\x00\x00\b\x00\t\x01\x12\x00\x03\x00\x00\x00\x01\x00\x01\x00\x00\x01\x12\x00\x03\x00\x00\x00\x01\x00\x01\x00\x00\x01\x1A\x00\x05\x00\x00\x00\x01\x00\x00\x00z\x01\e\x00\x05\x00\x00\x00\x01\x00\x00\x00\x82\x01(\x00\x03\x00\x00\x00\x01\x00\x02\x00\x00\x011\x00\x02\x00\x00\x00\x10\x00\x00\x00\x8A\x012\x00\x02\x00\x00\x00\x14\x00\x00\x00\x9A\x01<\x00\x02\x00\x00\x00\x10\x00\x00\x00\xAE\x02\x13\x00\x03\x00\x00\x00\x01\x00\x01\x00\x00\x00\x00\x00\xBE\x00H\x00\x00\x00\x01\x00\x00\x00H\x00\x00\x00\x01\x00\x00QuickTime 7.6.4\x002009:11:25 21:34:20\x00Mac OS X 10.5.8\x00\x00\a\x01\x03\x00\x03\x00\x00\x00\x01\x00\x06\x00\x00\x01\x1A\x00\x05\x00\x00\x00\x01\x00\x00\x01\x18\x01\e\x00\x05\x00\x00\x00\x01\x00\x00\x01 \x01(\x00\x03\x00\x00\x00\x01\x00\x02\x00\x00\x02\x01\x00\x04\x00\x00\x00\x01\x00\x00\x01(\x02\x02\x00\x04\x00\x00\x00\x01\x00\x00\x12\xBA\x02\x13\x00\x03\x00\x00\x00\x01\x00\x01 (...)
-> "HTTP/1.1 404 Not Found\r\n"
-> "cache-control: no-cache, no-store, max-age=0\r\n"
-> "content-length: 0\r\n"
-> "x-response-time: 4\r\n"
-> "x-connection-hash: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"
-> "date: Sat, 03 Sep 2022 19:03:25 GMT\r\n"
-> "server: tsa_b\r\n"
-> "connection: close\r\n"
-> "\r\n"
reading 0 bytes...
-> ""
read 0 bytes
Conn close

The command was this:
twurl -X POST -H "upload.twitter.com" "/1.1/media/upload.json" -f "/var/www/filemanager/photo.jpg" -F media -t

I checked my dashboard and the key shows that it has read & write permissions, the key was generated 2 years ago. I can post a status message from the same place, so I don’t think there’s anything wrong with the authentication.

Thanks for the help so far.

1 Like

Does the file definitely exist, and has read permissions, and is a valid jpg?

I just tried this exact command, with a different file name and it worked for me:

twurl -X POST -H "upload.twitter.com" "/1.1/media/upload.json" -f "/home/user/image.jpg" -F media -t

Absolutely no idea why you’d be getting a 404 to be honest!

I figured out that’s because a problem with Ruby 3.0 makes twurl ignore the -H parameter. I am trying everything to make it use version 2.7.1 with rbenv but it simply wont.
rbenv global shows 2.7.1, ruby -v shows 2.7.1, gem environment shows 2.7.1, but the output of the twurl command is still
platform: ruby 3.0.2 (x86_64-linux-gnu)
I even changed the symbolic link from /usr/bin/ruby to the 2.7.1 version under /home/user/.rbenv , still it picks up the 3.0.2 version. Sucks.

1 Like

I was able to fix it, not sure exactly how, but it seems I wiped out all twurl references, like its gem, and then I installed it again after having rbenv global set to 2.7.1, and I think that’s how twurl started using the proper version.

Thanks everyone for helping on this troubleshooting.

2 Likes