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

Help with posting an update with an image #58

Closed
tbwhite opened this Issue Apr 14, 2015 · 12 comments

Comments

8 participants
@tbwhite

tbwhite commented Apr 14, 2015

Can someone give me an example of how to post an update with an image using twurl ? This would be using media/upload and statuses/update.

@jaakko-sf

This comment has been minimized.

Contributor

jaakko-sf commented Apr 15, 2015

Hey @tbwhite,

Here's a sample from a post I just added to the TwitterDev forums.

twurl -H upload.twitter.com "/1.1/media/upload.json" -f ~/Desktop/B05iXOYCUAAGns4.jpg_large.jpg -F media -X POST

{
  "image": {
    "w": 1024,
    "h": 576,
    "image_type": "image/jpeg"
  },
  "media_id": 588185299844370432,
  "media_id_string": "588185299844370432",
  "size": 105489
}

Then to Tweet that media_id:

twurl "/1.1/statuses/update.json" -d "media_ids=588185299844370432&status=Sample Tweet with media_ids and twurl"

{
  "created_at": "Wed Apr 15 03:51:40 +0000 2015",
  "id": 588187910811299842,
  "id_str": "588187910811299842",
  "text": "Sample Tweet with media_ids and twurl http://t.co/fyPdMIfcNM",
...
    "media": [
      {
        "id": 588185299844370432,
        "id_str": "588185299844370432",
        "indices": [
          38,
          60
        ],
        "media_url": "http://pbs.twimg.com/media/CCmnafNUkAA0R-8.jpg",
        "media_url_https": "https://pbs.twimg.com/media/CCmnafNUkAA0R-8.jpg",
        "url": "http://t.co/fyPdMIfcNM",
        "display_url": "pic.twitter.com/fyPdMIfcNM",
        "expanded_url": "http://twitter.com/jaakkosf/status/588187910811299842/photo/1",
        "type": "photo",
        "sizes": {
          "thumb": {
            "w": 150,
            "h": 150,
            "resize": "crop"
          },
          "small": {
            "w": 340,
            "h": 191,
            "resize": "fit"
          },
          "medium": {
            "w": 600,
            "h": 337,
            "resize": "fit"
          },
          "large": {
            "w": 1024,
            "h": 576,
            "resize": "fit"
          }
        }
      }
    ]
  },
  "extended_entities": {
    "media": [
      {
        "id": 588185299844370432,
        "id_str": "588185299844370432",
        "indices": [
          38,
          60
        ],
        "media_url": "http://pbs.twimg.com/media/CCmnafNUkAA0R-8.jpg",
        "media_url_https": "https://pbs.twimg.com/media/CCmnafNUkAA0R-8.jpg",
        "url": "http://t.co/fyPdMIfcNM",
        "display_url": "pic.twitter.com/fyPdMIfcNM",
        "expanded_url": "http://twitter.com/jaakkosf/status/588187910811299842/photo/1",
        "type": "photo",
        "sizes": {
          "thumb": {
            "w": 150,
            "h": 150,
            "resize": "crop"
          },
          "small": {
            "w": 340,
            "h": 191,
            "resize": "fit"
          },
          "medium": {
            "w": 600,
            "h": 337,
            "resize": "fit"
          },
          "large": {
            "w": 1024,
            "h": 576,
            "resize": "fit"
          }
        }
      }
    ]
  },
...
}

Which resulted in this Tweet: https://twitter.com/jaakkosf/status/588187910811299842

@tbwhite

This comment has been minimized.

tbwhite commented Apr 15, 2015

Thanks for helping, unfortunately when I do this:

twurl -H upload.twitter.com "/1.1/media/upload.json" -f
C:\Users\Tom\Desktop\mm_image.png -F media -X POST

I get the following result:

{"request":"/1.1/media/upload.json","error":"not recognized."}

Any ideas ?

Also, I am using version 0.9.2

On 4/14/2015 9:13 PM, Jacob Petrie wrote:

Hey @tbwhite https://github.com/tbwhite,

Here's a sample from a post
https://twittercommunity.com/t/help-with-twurl-and-media-upload-json/35730/2?u=jaakkosf
I just added to the TwitterDev forums.

|twurl -H upload.twitter.com "/1.1/media/upload.json" -f
~/Desktop/B05iXOYCUAAGns4.jpg_large.jpg -F media -X POST|

{
"image": {
"w": 1024,
"h": 576,
"image_type": "image/jpeg"
},
"media_id": 588185299844370432,
"media_id_string": "588185299844370432",
"size": 105489
}

Then to Tweet that |media_id|:

|twurl "/1.1/statuses/update.json" -d
"media_ids=588185299844370432&status=Sample Tweet with media_ids and
twurl"|

{
"created_at": "Wed Apr 15 03:51:40 +0000 2015",
"id": 588187910811299842,
"id_str": "588187910811299842",
"text": "Sample Tweet with media_ids and twurl http://t.co/fyPdMIfcNM",
...
"media": [
{
"id": 588185299844370432,
"id_str": "588185299844370432",
"indices": [
38,
60
],
"media_url": "http://pbs.twimg.com/media/CCmnafNUkAA0R-8.jpg",
"media_url_https": "https://pbs.twimg.com/media/CCmnafNUkAA0R-8.jpg",
"url": "http://t.co/fyPdMIfcNM",
"display_url": "pic.twitter.com/fyPdMIfcNM",
"expanded_url": "http://twitter.com/jaakkosf/status/588187910811299842/photo/1",
"type": "photo",
"sizes": {
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"small": {
"w": 340,
"h": 191,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 337,
"resize": "fit"
},
"large": {
"w": 1024,
"h": 576,
"resize": "fit"
}
}
}
]
},
"extended_entities": {
"media": [
{
"id": 588185299844370432,
"id_str": "588185299844370432",
"indices": [
38,
60
],
"media_url": "http://pbs.twimg.com/media/CCmnafNUkAA0R-8.jpg",
"media_url_https": "https://pbs.twimg.com/media/CCmnafNUkAA0R-8.jpg",
"url": "http://t.co/fyPdMIfcNM",
"display_url": "pic.twitter.com/fyPdMIfcNM",
"expanded_url": "http://twitter.com/jaakkosf/status/588187910811299842/photo/1",
"type": "photo",
"sizes": {
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"small": {
"w": 340,
"h": 191,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 337,
"resize": "fit"
},
"large": {
"w": 1024,
"h": 576,
"resize": "fit"
}
}
}
]
},
...
}

Which resulted in this Tweet:
https://twitter.com/jaakkosf/status/588187910811299842


Reply to this email directly or view it on GitHub
#58 (comment).

@andypiper

This comment has been minimized.

Member

andypiper commented Apr 15, 2015

Try running the same command with a -t flag to trace out what is going on?

@andypiper

This comment has been minimized.

Member

andypiper commented Apr 15, 2015

I've just tried doing this on Windows 8, with Ruby installed via RubyInstaller, and twurl 0.9.2 from RubyGems. Tried via cmd.exe and powershell in case of some weird environment issue. I'm not able to reproduce.

twurl -H upload.twitter.com "/1.1/media/upload.json" -f C:\Users\andyp_000\Downloads\63950-640x360-london-icons2-640.jpg -F media -X POST

@tbwhite

This comment has been minimized.

tbwhite commented Apr 15, 2015

This is what I get when I run with the -t flag:

C:\Users\Tom>twurl -H upload.twitter.com "/1.1/media/upload.json" -f
C:\mm_image.png -F media -t -X POST
opening connection to upload.twitter.com:443...
opened
starting SSL for upload.twitter.com:443...
SSL established
<- "POST /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: OAuth gem
v0.4.7\r\nContent-T
ype: multipart/form-data,
boundary="00Twurl202752964603468149lruwT99"\r\nAutho
rization: OAuth oauth_body_hash="9%2FpdCObGVZ7nHfQjr2ciAkx8km8%3D",
oauth_cons
umer_key="R2wGDlvqiEtSslggXpSxWmEcW",
oauth_nonce="iuzgGLcOIeVjXAdBk6Fxb47KVh
Eu5b95chCJettvEY", oauth_signature="Nz1uIw1mewnTogxG1Cd1OBg4AxY%3D",
oauth_si
gnature_method="HMAC-SHA1", oauth_timestamp="1429102885",
oauth_token="2796
938558-hMq5LP9ncfC4dnNEJWwYcWcRzI1k6QbWZyKAe88",
oauth_version="1.0"\r\nConne
ction: close\r\nHost: upload.twitter.com\r\nContent-Length: 194\r\n\r\n"
<- "--00Twurl202752964603468149lruwT99\r\nContent-Disposition:
form-data; name=
"media"; filename="mm_image.png"\r\nContent-Type:
application/octet-stream\r
n\r\n\x89PNG\n\r\n--00Twurl202752964603468149lruwT99--\r\n"
-> "HTTP/1.1 400 Bad Request\r\n"
-> "cache-control: no-cache, no-store, must-revalidate, pre-check=0,
post-check=
0\r\n"
-> "connection: close\r\n"
-> "content-disposition: attachment; filename=json.json\r\n"
-> "content-encoding: gzip\r\n"
-> "content-length: 90\r\n"
-> "content-type: application/json;charset=utf-8\r\n"
-> "date: Wed, 15 Apr 2015 13:01:28 GMT\r\n"
-> "expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
-> "last-modified: Wed, 15 Apr 2015 13:01:28 GMT\r\n"
-> "pragma: no-cache\r\n"
-> "server: tsa_a\r\n"
-> "set-cookie: lang=en\r\n"
-> "set-cookie: guest_id=v1%3A142910288850359511; Domain=.twitter.com;
Path=/; E
xpires=Fri, 14-Apr-2017 13:01:28 UTC\r\n"
-> "status: 400 Bad Request\r\n"
-> "strict-transport-security: max-age=631138519\r\n"
-> "x-access-level: read-write\r\n"
-> "x-connection-hash: 1c8e5ff126bf394bf1fb97fc95209b02\r\n"
-> "x-frame-options: SAMEORIGIN\r\n"
-> "x-response-time: 23\r\n"
-> "x-transaction: d7f66e9f1bfa400e\r\n"
-> "x-tsa-request-body-time: 6\r\n"
-> "x-twitter-response-tags: BouncerCompliant\r\n"
-> "x-xss-protection: 1; mode=block\r\n"
-> "\r\n"
reading 90 bytes...
-> ""
->
"\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x00\xAAV_J-,M-.Q\xB2R\x8A\xD17\xD43\x8C\x
D1\xCFMM\xC9L\x8C\xD1/-\xC8\xC9OL\xD1\xCB_\xCE\xCFS\xD2QJ-*\xCA/\x02\xAA\xC9\xCB
/Q(JM\xCEO\xCF\xCB\xACJM\xD1S\xAA\x05\x00\x00\x00\xFF\xFF\x03\x00\xED\xAF\x8F\xF
8A\x00\x00\x00"
{"request":"/1.1/media/upload.json","error":"not recognized."}read 90
bytes
Conn close

On 4/15/2015 2:54 AM, Andy Piper wrote:

Try running the same command with a |-t| flag to trace out what is
going on?


Reply to this email directly or view it on GitHub
#58 (comment).

@robdevelop

This comment has been minimized.

robdevelop commented Apr 20, 2015

Did you achieve any resolution with this?

I am having what looks to be the exact same issue.
I have included my details over on TwitterCommunity
https://twittercommunity.com/t/help-with-twurl-and-media-upload-json/35730

Although a novice, you would think the twurl example provided by Twitter would actually work, but in this case I have no clue as to what is wrong.

@sebagomez

This comment has been minimized.

sebagomez commented Jun 4, 2015

I'm using twurl -H upload.twitter.com "/1.1/media/upload.json" -f London.jpg -F media -X POST -t and I'm getting {"request":"\/1.1\/media\/upload.json","error":"media type unrecognized."}

So frustrating when an example doesn't work :(

p.s: I get the same with both jpg and png files

@darthgooch

This comment has been minimized.

darthgooch commented Oct 24, 2015

I am also having this issue, and have tried ~5 different computers.

I am using the following:
Windows 7 x64 Enterprise
twurl 0.9.3
Ruby 2.2.3p173 (2015-08-18 revision 51636) [i386-mingw32]

C:\Ruby22\bin>twurl -H upload.twitter.com /1.1/media/upload.json -f C:\Advert.jpg -F media -t -X POST
opening connection to upload.twitter.com:443...
opened
starting SSL for upload.twitter.com:443...
SSL established
<- "POST /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: OAuth gem v0.4.7\r\n
Content-Type: multipart/form-data, boundary="00Twurl940379708868074689lruwT99"\r\nAuthorization: OAuth oauth_body_hash="yUnO9YGhrzkyC0ijJ5eOVt2DPK0%
3D", oauth_consumer_key="sV3KHuUeILt3ozSypNiWO42k1", oauth_nonce="RiaVR95C4ZmRDQA14JMoPzzT3MkoPHZmM0qufU5pfk", oauth_signature="eUS6RMMgPWPKF2xbf
14Kx6yjoNo%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1445704701", oauth_token="3090409445-JgOV6x8yRQGemhHHlfNgchkyl6FMJEoivtR1TVv
", oauth_version="1.0"\r\nConnection: close\r\nHost: upload.twitter.com\r\nContent-Length: 264\r\n\r\n"
<- "--00Twurl940379708868074689lruwT99\r\nContent-Disposition: form-data; name="media"; filename="Advert.jpg"\r\nContent-Type: application/octet-st
ream\r\n\r\n\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xFF\xE10sExif\x00\x00MM\x00_\x00\x00\x00\b\x00\f\x01\x0F\x00\x02\x00\x00\x00
\x06\x00\x00\x00\x9E\x01\x10\x00\x02\x00\x00\x00\n\x00\x00\x00\xA4\x01\x12\x00\x03\x00\x00\x00\x01\x00\x01\x00\x00\x01\r\n--00Twurl940379708868074689lr
uwT99--\r\n"
-> "HTTP/1.1 400 Bad Request\r\n"
-> "cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0\r\n"
-> "connection: close\r\n"
-> "content-disposition: attachment; filename=json.json\r\n"
-> "content-encoding: gzip\r\n"
-> "content-length: 96\r\n"
-> "content-type: application/json;charset=utf-8\r\n"
-> "date: Sat, 24 Oct 2015 16:38:33 GMT\r\n"
-> "expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
-> "last-modified: Sat, 24 Oct 2015 16:38:33 GMT\r\n"
-> "pragma: no-cache\r\n"
-> "server: tsa_b\r\n"
-> "set-cookie: lang=en; Path=/\r\n"
-> "set-cookie: guest_id=v1%3A144570471311594528; Domain=.twitter.com; Path=/; Expires=Mon, 23-Oct-2017 16:38:33 UTC\r\n"
-> "status: 400 Bad Request\r\n"
-> "strict-transport-security: max-age=631138519\r\n"
-> "vary: Origin\r\n"
-> "x-access-level: read-write\r\n"
-> "x-connection-hash: 5f68bfce7f428dfbf044a0880aaf7914\r\n"
-> "x-frame-options: SAMEORIGIN\r\n"
-> "x-rate-limit-limit: 415\r\n"
-> "x-rate-limit-remaining: 412\r\n"
-> "x-rate-limit-reset: 1445708219\r\n"
-> "x-response-time: 18\r\n"
-> "x-transaction: 5d99fa0a1a3d61c5\r\n"
-> "x-tsa-request-body-time: 2\r\n"
-> "x-twitter-response-tags: BouncerCompliant\r\n"
-> "x-xss-protection: 1; mode=block\r\n"
-> "\r\n"
reading 96 bytes...
-> ""
-> "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x00\xAAV_J-,M-.Q\xB2R\x8A\xD17\xD43\x8C\xD1\xCFMM\xC9L\x8C\xD1/-\xC8\xC9OL\xD1\xCB_\xCE\xCFS\xD2QJ-\xCA/\x02\xA
A\x01K
\x94T\x16\xA4_\x94\xE6\x15\xA5&\xE7\xA7\xE7eV\xA5\xA6\xE8)\xD5\x02\x00\x00\x00\xFF\xFF\x03\x00\xAC\x7F\t\xF4J\x00\x00\x00"
{"request":"/1.1/media/upload.json","error":"media type unrecognized."}read 96 bytes
Conn close

C:\Ruby22\bin>twurl -v
0.9.3

C:\Ruby22\bin>ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [i386-mingw32]

@sebagomez

This comment has been minimized.

sebagomez commented Oct 27, 2015

Just so you know it worked for me. I was using the code from github when I got those errors. After that I decided to install Ruby from chocolatey. I finally got v2.1.6 and from there twurl v0.9.3 and it worked!.
I didn't mind looking for what was NOT working before... I'm just happy it works now.
x64 Windows 10 box

@joonjoonjoon

This comment has been minimized.

joonjoonjoon commented Jul 16, 2016

I get this error, and even on ruby 2.1.6 and Twurl 0.9.3 or 0.9.2, I cannot get past the 'media type unrecognized" issue. I can post status updates, but not images. Anyone figure out why this could be happening? I tried many images, types, stripping EXIF, encodings, etc... and nothing works.

@nvanesch

This comment has been minimized.

nvanesch commented Sep 19, 2016

my problem on windows is ruby did not binary read the full file so only sent the first 100 bytes or so. I had to change to binary file read (instead of just File.read I needed to use File.open with "rb" binary option.

on windows
edit C:\tools\ruby23\lib\ruby\gems\2.3.0\gems\twurl-0.9.3\lib\twurl\oauth_client.rb
around line 100 replace with the below

          # http://stackoverflow.com/questions/7157207/how-can-i-read-a-file-with-ruby need to read in binary
          file = File.open(filename, "rb")
          if options.upload['base64']
            #enc = Base64.encode64(File.read(filename))
            enc = Base64.encode64(file.read())
            multipart_body << enc
          else
            #multipart_body << File.read(filename)
            multipart_body << file.read()
          end
          file.close
@andypiper

This comment has been minimized.

Member

andypiper commented Sep 14, 2017

Closing for age / inability to repro - please open a new issue if this still occurs with 0.9.3

@andypiper andypiper closed this Sep 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment