Giter Club home page Giter Club logo

twurl's Introduction

Twurl

MIT License Gem Version CI

Twurl is like curl, but tailored specifically for the Twitter API. It knows how to grant an access token to a client application for a specified user and then sign all requests with that access token.

It also provides other development and debugging conveniences such as defining aliases for common requests, as well as support for multiple access tokens to easily switch between different client applications and Twitter accounts.

Installing Twurl

Twurl can be installed using RubyGems:

gem install twurl

Getting Started

If you haven't already, the first thing to do is apply for a developer account to access Twitter APIs:

https://developer.twitter.com/en/apply-for-access

After you have that access you can create a Twitter app and generate a consumer key and secret.

When you have your consumer key and its secret you authorize your Twitter account to make API requests with that consumer key and secret.

twurl authorize --consumer-key key       \
                --consumer-secret secret

This will return an URL that you should open up in your browser. Authenticate to Twitter, and then enter the returned PIN back into the terminal. Assuming all that works well, you will be authorized to make requests with the API. Twurl will tell you as much.

Making Requests

The simplest request just requires that you specify the path you want to request.

twurl /1.1/statuses/home_timeline.json

Similar to curl, a GET request is performed by default.

You can implicitly perform a POST request by passing the -d option, which specifies POST parameters.

twurl -d 'status=Testing twurl' /1.1/statuses/update.json

You can explicitly specify what request method to perform with the -X (or --request-method) option.

twurl -X POST /1.1/statuses/destroy/1234567890.json

Using Bearer Tokens (Application-only authentication)

You can generate a bearer token using --bearer option in combination with the authorize subcommand.

twurl authorize --bearer --consumer-key key       \
                         --consumer-secret secret

And then, you can make a request using a generated bearer token using --bearer request option.

twurl --bearer '/1.1/search/tweets.json?q=hello'

To list your generated bearer tokens, you can use the bearer_tokens subcommand.

twurl bearer_tokens

This will print a pair of consumer_key and its associated bearer token. Note, tokens are omitted from this output.

Accessing Different Hosts

You can access different hosts for other Twitter APIs using the -H flag.

twurl -H "ads-api.twitter.com" "/7/accounts"

Uploading Media

To upload binary files, you can format the call as a form post. Below, the binary is "/path/to/media.jpg" and the form field is "media":

twurl -H "upload.twitter.com" -X POST "/1.1/media/upload.json" --file "/path/to/media.jpg" --file-field "media"

Creating aliases

twurl alias h /1.1/statuses/home_timeline.json

You can then use "h" in place of the full path.

twurl h

Paths that require additional options (such as request parameters, for example) can be used with aliases the same as with full explicit paths, just as you might expect.

twurl alias tweet /1.1/statuses/update.json
twurl tweet -d "status=Aliases in twurl are convenient"

Changing your default profile

The first time you authorize a client application to make requests on behalf of your account, twurl stores your access token information in its ~/.twurlrc file. Subsequent requests will use this profile as the default profile. You can use the accounts subcommand to see what client applications have been authorized for what user names:

twurl accounts
  noradio
    HQsAGcBm5MQT4n6j7qVJw
    hhC7Koy2zRsTZvQh1hVlSA (default)
  testiverse
    guT9RsJbNQgVe6AwoY9BA

Notice that one of those consumer keys is marked as the default. To change the default use the set subcommand, passing then either just the username, if it's unambiguous, or the username and consumer key pair if it isn't unambiguous:

twurl set default testiverse
twurl accounts
  noradio
    HQsAGcBm5MQT4n6j7qVJw
    hhC7Koy2zRsTZvQh1hVlSA
  testiverse
    guT9RsJbNQgVe6AwoY9BA (default)
twurl set default noradio HQsAGcBm5MQT4n6j7qVJw
twurl accounts
  noradio
    HQsAGcBm5MQT4n6j7qVJw (default)
    hhC7Koy2zRsTZvQh1hVlSA
  testiverse
    guT9RsJbNQgVe6AwoY9BA

Profiles and Bearer Tokens

While changing the default profile allows you to select which access token (OAuth1.0a) to use, bearer tokens don't link to any user profiles as the Application-only authentication doesn't require user context. That is, you can make an application-only request regardless of your default profile if you specify the -c (--consumer-key) option once you generate a bearer token with this consumer key. By default, twurl reads the current profile's consumer key and its associated bearer token from ~/.twurlrc file.

Contributors

Marcel Molina / @noradio

Erik Michaels-Ober / @sferik

and there are many more!

twurl's People

Contributors

alzeih avatar andypiper avatar bcomnes avatar caniszczyk avatar esbie avatar flaviomartins avatar j3h avatar jaakko-sf avatar jimmoffitt avatar kurrik avatar majg0 avatar marcel avatar mishina2228 avatar nimitalt avatar passy avatar pavanky avatar raethlo avatar sanmai avatar sferik avatar smaeda-ks avatar sylvaincarle avatar twitter-service avatar woparry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twurl's Issues

Any way to see both Access Token + Secret?

Using Twurl we can see our access tokens for particular applications - but is there any way to see our Access Token Secret as well?

Is there any way at all to see our Access Token Secrets (besides the dev.twitter application page - which shows the secret ONLY if you have have created the application )?

Issue when i try authz

/usr/lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo: Name or service not known (SocketError)

i use my own host , linke this:

twurl authorize -u myname -p passwd --consumer-key Xdhr9Hz7DOw --consumer-secret 2TnM -H https://baga3.org/b3tt/t/

How could i usr twurl with a proxy

Dear all,

i usr twurl in China,so i must use HTTP Porxy to authorize and send data,but i cannt find howto about proxy.

so , anyone would help me ?

twurl -d "status=Tweet from twurl" /1/statuses/update.xml breaks

I did sudo gem install twurl and everything when fine and version 0.6.7 is successfully installed :)
Then authorized the app twurl authorize -u X -p X --consumer-key X --consumer-secret X and supplied the pin and got : Authorization successful Yay!

Sadly

twurl -d "status=Tweet from twurl" /1/statuses/update.xml

leads to

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load': syntax error on line 14, col -1: `' (ArgumentError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:144:in `load_file'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:143:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:143:in `load_file'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.7/bin/../lib/twurl/rcfile.rb:18:in `load'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.7/bin/../lib/twurl/rcfile.rb:30:in `initialize'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.7/bin/../lib/twurl/oauth_client.rb:6:in `new'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.7/bin/../lib/twurl/oauth_client.rb:6:in `rcfile'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.7/bin/../lib/twurl/oauth_client.rb:12:in `load_from_options'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.7/bin/../lib/twurl/cli.rb:18:in `dispatch'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.7/bin/../lib/twurl/cli.rb:14:in `run'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.7/bin/twurl:4
from /usr/bin/twurl:19:in `load'
from /usr/bin/twurl:19

Have tried other commands like twurl /1/statuses/home_timeline.xml and it works flawless ... I have 0 ruby knowledge so I can't help ;(

Twitter REST API v1 is no longer active.

I was using Twurl successfully for several days, but I have bad timing, because the REST API has been depricated as of June 11. The error I now receive when trying to use Twurl is as follows:

The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.

Which directs me to the overview site for API v1.1. Unfortunately migrating this on my own is way over my head, so I'm hoping some people who are using Twurl are able to do this, or perhaps can offer an alternative. Thank you.

Feature Request: "pretend mode" that outputs OAuth authorization header

By executing Twurl with a pre-loaded access token and consumer keyset while including a "--pretend" or "--only-generate-http-headers" option it would output a string simply consisting of the HTTP Authorization header. Developers could then use Twurl as a pipe for shell scripts with the ultimate destination of curl for the additional features it offers as an HTTP client.

Anonymous requests

Twitter for Mac seems to support issuing some commands in anonymous mode. Some of them are certainly possible with curl:

# curl http://api.twitter.com/1/account/rate_limit_status.json
{"hourly_limit":150,"reset_time":"...
# curl http://api.twitter.com/1/related_results/show/123456.json
[{"results":[{"score":1.0,...

Would it be possible to have twurl do the same?

Currently:

# twurl /1/account/rate_limit_status.json
You must authorize first

Parsing certain fields

Is there a way to use Twurl to parse only certain fields from the JSON? I want to run something like
twurl "/1.1/statuses/show/[TWEET ID].json"

and have it spit out only the following from the json:

"id_str", "text", "location", "geo", "coordinates", and "place"?

Unable to Enter Authorization PIN

I receive the following output in my terminal and am unable to enter my Authorization PIN.
/usr/local/var/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/twurl-0.9.2/lib/twurl/oauth_client.rb:136:in `gets': Is a directory @ io_fillbuf - fd:9 / (Errno::EISDIR)
    from /usr/local/var/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/twurl-0.9.2/lib/twurl/oauth_client.rb:136:in `gets'
    from /usr/local/var/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/twurl-0.9.2/lib/twurl/oauth_client.rb:136:in `perform_pin_authorize_workflow'
    from /usr/local/var/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/twurl-0.9.2/lib/twurl/oauth_client.rb:123:in `rescue in exchange_credentials_for_access_token'
    from /usr/local/var/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/twurl-0.9.2/lib/twurl/oauth_client.rb:120:in `exchange_credentials_for_access_token'
    from /usr/local/var/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/twurl-0.9.2/lib/twurl/authorization_controller.rb:6:in `dispatch'
    from /usr/local/var/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/twurl-0.9.2/lib/twurl/abstract_command_controller.rb:7:in `dispatch'
    from /usr/local/var/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/twurl-0.9.2/lib/twurl/cli.rb:38:in `dispatch'
    from /usr/local/var/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/twurl-0.9.2/lib/twurl/cli.rb:21:in `run'
    from /usr/local/var/rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/twurl-0.9.2/bin/twurl:4:in `<top (required)>'
    from /usr/local/var/rbenv/versions/2.1.4/bin/twurl:23:in `load'
    from /usr/local/var/rbenv/versions/2.1.4/bin/twurl:23:in `<main>'

I am running Ruby Version:
ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-darwin14.0]

How do I fix this so I can get the PIN prompt inside terminal?

Incorrect Signature

Ever since a few days ago my Twurl stopped working, and now it keeps showing incorrect signature. Any ideas what could be wrong?

-F does not default to "media" (or any other value)

If you do not specify -F, no default value is provided. This is in contrast with the command-line documentation, which states:

-F, --file-field [field_name]    Specify the file field for the upload to be included within (default: media)

Post Tweet with Media and Geo Tag

Hello,

I would like to be able to post a tweet with an image and that is geo-tagged.

twurl -X POST "/1.1/statuses/update_with_media.json" --file pic.png -file-field "media[]" -d "status=Hello" geocode=39.45,-95.16

Thanks.

Twurl installation breaks during "twurl authorize" using "username" literally

Twurl has been working fine up until I tried to add a new twitter account and made an error durong the process, forgetting to replace the word username with my twitter username, but still using all the rest of my credentials as same as my other twitter account.

Reinstalling ruby, yaml & twurl does not fix the problem so now I have no idea what to do, here is whet i remember doing

twurl authorize -u username -p password \

                --consumer-key the_key       \
                --consumer-secret the_secret

MY MISTAKE WAS TO USE THE WORD "username" accidentally for my twitter-name, then when I tried to list my accounts this happened and continues to happen.....

twurl accounts

/usr/lib/ruby/1.8/yaml.rb:133:in load': syntax error on line 21, col -1:' (ArgumentError)
from /usr/lib/ruby/1.8/yaml.rb:133:in load' from /usr/lib/ruby/1.8/yaml.rb:144:inload_file'
from /usr/lib/ruby/1.8/yaml.rb:143:in open' from /usr/lib/ruby/1.8/yaml.rb:143:inload_file'
from /usr/lib/ruby/gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/rcfile.rb:18:in load' from /usr/lib/ruby/gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/rcfile.rb:30:ininitialize'
from /usr/lib/ruby/gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/oauth_client.rb:6:in new' from /usr/lib/ruby/gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/oauth_client.rb:6:inrcfile'
from /usr/lib/ruby/gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/oauth_client.rb:12:in load_from_options' from /usr/lib/ruby/gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/cli.rb:18:indispatch'
from /usr/lib/ruby/gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/cli.rb:14:in run' from /usr/lib/ruby/gems/1.8/gems/twurl-0.7.0/bin/twurl:4 from /usr/bin/twurl:19:inload'
from /usr/bin/twurl:19

REINSTALLED RUBY, YAML, TWURL, OAUTH ETC - error continues to happen.

Can you please help fix this or identify some other places I can clean out i.e. local credential storage file or something.

TWURL does not seem to have a rollback facility, or an "unauthorise" command,

I really need your help.

Thanks
R.

HTTP Post data not encoded properly under 1.9.3

I believe I've found a bug in twurl running under ruby 1.9.3 regarding content type encoding. Specifically, I've found that reqeusts with an asterisk ('*') in the HTTP body fail under 1.9.3 but succeed under 1.8.7. I'm using the following command to test:

$ ruby --version && ./twurl --version && ./twurl /1.1/statuses/update\.json -d "status=An Introduction to the A* algorithm http://www.redblobgames.com/pathfinding/a-star/introduction.html"  -t

Under 1.8.7, I get:

ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin13.1.0], MBARI 0x6770, Ruby Enterprise Edition 2011.03
0.9.2
opening connection to api.twitter.com...
opened
<- "POST /1.1/statuses/update.json HTTP/1.1\r\nAccept: */*\r\nConnection: close\r\nUser-Agent: OAuth gem v0.4.7\r\nContent-Type: application/x-www-form-urlencoded\r\nAuthorization: OAuth oauth_consumer_key=\"###\", oauth_nonce=\"###
\", oauth_signature=\"###\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"###\", oauth_token=\"###\", oauth_version=\"1.0\"\r\nContent-Length: 147\r\nHost: api.twi
tter.com\r\n\r\n"
<- "status=An%20Introduction%20to%20the%20A%2a%20algorithm%20http%3a%2f%2fwww.redblobgames.com%2fpathfinding%2fa-star%2fintroduction.html"
-> "HTTP/1.1 200 OK\r\n"
... [ rest of http response ]

Under 1.9.3, I get:

ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin13.1.0]
0.9.2
opening connection to api.twitter.com...
opened
<- "POST /1.1/statuses/update.json HTTP/1.1\r\nAccept: */*\r\nUser-Agent: OAuth gem v0.4.7\r\nContent-Type: application/x-www-form-urlencoded\r\nAuthorization: OAuth oauth_consumer_key=\"###\", oauth_nonce=\"###\", oauth_signature=\"###\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"###\", oauth_token=\"###\", oauth_version=\"1.0\"\r\nConnection: close\r\nHost: api.twitter.com\r\nContent-Length: 133\r\n\r\n"
<- "status=An+Introduction+to+the+A*+algorithm+http%3A%2F%2Fwww.redblobgames.com%2Fpathfinding%2Fa-star%2Fintroduction.html"
-> "HTTP/1.1 401 Unauthorized\r\n"
... [ rest of http response ]

Note that in 1.9.3, the status parameter in the HTTP body is not actually form-urlencoded even though that's the content-type, whereas, in 1.8.7, it is.

Feature Request: username selection command line option

Hi,

The two step process to ensure the correct username is used (in a script for example):

twurl set default username
twurl tweet -d status="why's that?"

Seems a bit awkward. Couldn't -u be used for this or that would be curly?

Trouble getting twurl utility working with Ads API Advertiser API api ads

coreyf@frewbook-pro /tmp> gem i twurl --source http://rubygems.org
Successfully installed twurl-0.9.3
Parsing documentation for twurl-0.9.3
Done installing documentation for twurl after 0 seconds
1 gem installed
coreyf@frewbook-pro /tmp> twurl authorize --consumer-key [my consumer key] --consumer-secret [my secret key]
Go to [url here] and paste in the supplied PIN
[pin here]
Authorization successful
coreyf@frewbook-pro /tmp> twurl -H ads-api-sandbox.twitter.com /0/accounts/
{"errors":[{"code":"UNAUTHORIZED_CLIENT_APPLICATION","message":"The client application making this request does not have access to this API"}],"request":{"params":{}}}

Why does my client not have access to this API?

Where should I run rake dist:gem?

I run it from the twurl-0.8.1 directory, but I get these errors:

fatal: Not a git repository (or any of the parent directories): .git
rake aborted!
Don't know how to build task 'dist:gem'

how to specify geocode in twurl

I have search query with geocode. How to specify it in the twurl ?

Is following the right way ?

twurl "/1.1/search/tweets.json?q=UCLAAthletics OR uclafootball&geocode=34.161389,-118.1675,5mi"

Set custom path for .twurlrc location

I was wondering if it'd be possible for one of you to add an argument to twurl that lets you specify your .twurlrc directory? I'd do it myself but I'm not really a ruby guy... I found my way around well enough to hard-code in where I needed it to look though, so not exactly urgent, but I think it'd be cool and if either of you agree and have the time it'd be really good.

Something like -P /home/user/.twurlrc would be super.

Note: the reason for this request is that I'm calling twurl from another service that strips out all ENV stuff, including location of homedir.

Can't authorize

I just installed Twurl and am getting the following error when I try to authorize:

/Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/helper.rb:37:in <=>': undefined method<=>' for :x_auth_username:Symbol (NoMethodError)
from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/helper.rb:37:in sort' from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/helper.rb:37:innormalize'
from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/consumer.rb:359:in create_http_request' from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/consumer.rb:187:increate_signed_request'
from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/consumer.rb:159:in request' from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/consumer.rb:194:intoken_request'
from /Library/Ruby/Gems/1.8/gems/twurl-0.8.0/bin/../lib/twurl/oauth_client.rb:85:in exchange_credentials_for_access_token' from /Library/Ruby/Gems/1.8/gems/twurl-0.8.0/bin/../lib/twurl/authorization_controller.rb:6:indispatch'
from /Library/Ruby/Gems/1.8/gems/twurl-0.8.0/bin/../lib/twurl/abstract_command_controller.rb:7:in dispatch' from /Library/Ruby/Gems/1.8/gems/twurl-0.8.0/bin/../lib/twurl/cli.rb:31:indispatch'
from /Library/Ruby/Gems/1.8/gems/twurl-0.8.0/bin/../lib/twurl/cli.rb:14:in run' from /Library/Ruby/Gems/1.8/gems/twurl-0.8.0/bin/twurl:4 from /usr/bin/twurl:19:inload'
from /usr/bin/twurl:19

Error 32 in /1.1/statuses/update.json

I want to POST a status via twurl but everything I get is
{"errors":[{"code":32,"message":"Could not authenticate you."}]}.
I checked my consumer key and secret multiple times, still it doesn't work. Does anyone know what's wrong?

How to handle timeout issue

I'm using twurl via the Mac Terminal and everything works fine except that I get timeout errors (for certain keywords) when accessing the search API. Is there anyway to rescue these timeout errors or set the timeout-treshold higher?

twurl -t -d track='very_rare_keyword' -H stream.twitter.com /1.1/statuses/filter.json >filename.json

yields (after roughly have a minute)

/usr/lib/ruby/1.8/timeout.rb:64:in rbuf_fill': execution expired (Timeout::Error) from /usr/lib/ruby/1.8/net/protocol.rb:134:inrbuf_fill'
from /usr/lib/ruby/1.8/net/protocol.rb:104:in read_all' from /usr/lib/ruby/1.8/net/http.rb:2228:inread_body_0'
from /usr/lib/ruby/1.8/net/http.rb:2181:in read_body' from /usr/lib/ruby/gems/1.8/gems/twurl-0.8.3/bin/../lib/twurl/request_controller.rb:14:inperform_request'
from /usr/lib/ruby/1.8/net/http.rb:1054:in request' from /usr/lib/ruby/1.8/net/http.rb:2144:inreading_body'
from /usr/lib/ruby/1.8/net/http.rb:1053:in request' from /usr/lib/ruby/1.8/net/http.rb:1037:inrequest'
from /usr/lib/ruby/1.8/net/http.rb:543:in start' from /usr/lib/ruby/1.8/net/http.rb:1035:inrequest'
from /usr/lib/ruby/gems/1.8/gems/twurl-0.8.3/bin/../lib/twurl/oauth_client.rb:80:in perform_request_from_options' from /usr/lib/ruby/gems/1.8/gems/twurl-0.8.3/bin/../lib/twurl/request_controller.rb:13:inperform_request'
from /usr/lib/ruby/gems/1.8/gems/twurl-0.8.3/bin/../lib/twurl/request_controller.rb:9:in dispatch' from /usr/lib/ruby/gems/1.8/gems/twurl-0.8.3/bin/../lib/twurl/abstract_command_controller.rb:7:indispatch'
from /usr/lib/ruby/gems/1.8/gems/twurl-0.8.3/bin/../lib/twurl/cli.rb:38:in dispatch' from /usr/lib/ruby/gems/1.8/gems/twurl-0.8.3/bin/../lib/twurl/cli.rb:21:inrun'
from /usr/lib/ruby/gems/1.8/gems/twurl-0.8.3/bin/twurl:4
from /usr/bin/twurl:19:in `load'
from /usr/bin/twurl:19

Trouble authorizing

I am by no means a programmer so please bear with me on this one. I was able to install Twurl with no trouble, but I'm having trouble with the authorization process.

After returning the URL to visit to authorize, I get the following error:

and paste in the supplied PIN
/Library/Ruby/Gems/1.8/gems/twurl-0.6.3/bin/../lib/twurl/oauth_client.rb:99:in gets': Is a directory - / (Errno::EISDIR) from /Library/Ruby/Gems/1.8/gems/twurl-0.6.3/bin/../lib/twurl/oauth_client.rb:99:inperform_pin_authorize_workflow'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.3/bin/../lib/twurl/oauth_client.rb:86:in exchange_credentials_for_access_token' from /Library/Ruby/Gems/1.8/gems/twurl-0.6.3/bin/../lib/twurl/authorization_controller.rb:6:indispatch'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.3/bin/../lib/twurl/abstract_command_controller.rb:7:in dispatch' from /Library/Ruby/Gems/1.8/gems/twurl-0.6.3/bin/../lib/twurl/cli.rb:31:indispatch'
from /Library/Ruby/Gems/1.8/gems/twurl-0.6.3/bin/../lib/twurl/cli.rb:14:in run' from /Library/Ruby/Gems/1.8/gems/twurl-0.6.3/bin/twurl:4 from /usr/bin/twurl:19:inload'
from /usr/bin/twurl:19

I believe I'm supposed to enter the supplied PIN, but never get asked for it.

I'd really appreciate any help you might be able to provide.

-q argument has no effect

For some reason the --quiet / -q option is not working for me. Even with the flag, it outputs everything.

Side note: if there is an error anywhere it may still be nice to output to stderr or at least give a non-zero exit code.

Ubuntu 10.10 install issues

I'm having trouble getting twurl to install cleanly on Ubuntu 10.10. Unfortunately, I've never touched Ruby and am having trouble figuring out the issue (wasted a day so far and feel like I made zero progress diagnosing the problem). I managed to get twurl working perfectly on my snow leopard laptop on the first go. Is there a linux distro you can recommend ... one where Ruby/twurl installs cleanly?

FYI ... the issue with Ubuntu is odd. First off, I can't seem to update gem. It is 1.3.7 on my Ubuntu box but 1.4.1 on my Mac. When I used the install commands for twurl, I see a success message on Ubuntu:

sudo gem i twurl --source http://rubygems.org
Successfully installed twurl-0.6.2
1 gem installed
Installing ri documentation for twurl-0.6.2...
Installing RDoc documentation for twurl-0.6.2...

However, when I do "which twurl", I don't see anything. On Mac, I see:
/usr/bin/twurl

I'd really appreciate an alternative distro recommendation and/or help getting this to work on Ubuntu.

P.S. Thanks for this excellent tool.

Tweet with image fails with error 32

My tweets without images work fine and with images fail.

I'd uploaded my image:

$ twurl -H upload.twitter.com -X POST "/1.1/media/upload.json" --file "../../../blog/API SDK download in Developer Portal.png" --file-field "media"
{"media_id":852314091490168833,"media_id_string":"852314091490168833","size":94927,"expires_after_secs":86400,"image":{"image_type":"image/png","w":914,"h":646}}

Then when I twurl without the image - this works great.

With the image - it fails:

$ twurl "/1.1/statuses/update.json" -d "media_ids=852314091490168833&status=Sample Tweet with media_ids and twurl"
{"errors":[{"code":32,"message":"Could not authenticate you."}]}

The application has both Read and Write permissions.

Any ideas on what's going on?

Feature request: Pretty print output

It would be nice if twurl had an option to reformat the output to be more human readable. Just parse the JSON / XML enough to add newlines and indenting. No semantic understanding needed.

Please add support for the new metadata endpoint

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.

Invalid Json output?

I have been using twurl for over a year to run a series of twitter searches. I feed the json output to a json2csv system, and it started complaining about a month ago that the json output is invalid. I've taken the output of a number of searches and fed them into multiple json2csv systems online and they all say invalid json.

Did something happen between Nov 5 & 15th that would have changed this? I updated to the latest version of twurl and that didn't fix it.

I know squat about json, so I can't look at it and see what's wrong. All I know is all the json converters are complaining it's not valid. I'll cut and paste an example below.

{"statuses":[{"metadata":{"iso_language_code":"en","result_type":"recent"},"created_at":"Wed Dec 17 21:50:34 +0000 2014","id":545335269185294337,"id_str":"545335269185294337","text":"This is DIY data disaster recovery. @ AHK Electronic Sheetmetal http://t.co/HfDCqKIu5p","source":"\u003ca href="http://instagram.com" rel="nofollow"\u003eInstagram\u003c/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":14364184,"id_str":"14364184","name":"Jason Sholl","screen_name":"jasonsholl","location":"San Jose, CA","profile_location":null,"description":"Founder of @ProReferee, #television & #digitalmedia Executive, 15-time @TellyAwards winning #producer/#director, soccer #referee, @SCUGradBiz EMBA '14","url":"http://t.co/QCmDPcqoce","entities":{"url":{"urls":[{"url":"http://t.co/QCmDPcqoce","expanded_url":"http://www.jasonsholl.com","display_url":"jasonsholl.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":142,"friends_count":155,"listed_count":13,"created_at":"Fri Apr 11 20:13:57 +0000 2008","favourites_count":18,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":2557,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"0E0D02","profile_background_image_url":"http://pbs.twimg.com/profile_background_images/378800000086223477/d3337f4a0488aaada2c7e54b6bce1f14.jpeg","profile_background_image_url_https":"https://pbs.twimg.com/profile_background_images/378800000086223477/d3337f4a0488aaada2c7e54b6bce1f14.jpeg","profile_background_tile":false,"profile_image_url":"http://pbs.twimg.com/profile_images/523598663172382720/XtR_sa96_normal.jpeg","profile_image_url_https":"https://pbs.twimg.com/profile_images/523598663172382720/XtR_sa96_normal.jpeg","profile_banner_url":"https://pbs.twimg.com/profile_banners/14364184/1411005930","profile_link_color":"5681CC","profile_sidebar_border_color":"BEDFB6","profile_sidebar_fill_color":"0E0D02","profile_text_color":"39BD91","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":{"type":"Point","coordinates":[37.1432508,-121.6488283]},"coordinates":{"type":"Point","coordinates":[-121.6488283,37.1432508]},"place":{"id":"e872bcd2497287a7","url":"https://api.twitter.com/1.1/geo/id/e872bcd2497287a7.json","place_type":"city","name":"Morgan Hill","full_name":"Morgan Hill, CA","country_code":"US","country":"United States","contained_within":[],"bounding_box":{"type":"Polygon","coordinates":[[[-121.70014,37.088404],[-121.583333,37.088404],[-121.583333,37.16931],[-121.70014,37.16931]]]},"attributes":{}},"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[{"url":"http://t.co/HfDCqKIu5p","expanded_url":"http://instagram.com/p/wuToh7LM0C/","display_url":"instagram.com/p/wuToh7LM0C/","indices":[64,86]}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"metadata":{"iso_language_code":"en","result_type":"recent"},"created_at":"Wed Dec 17 15:53:20 +0000 2014","id":545245366191661056,"id_str":"545245366191661056","text":"Fun, brief video about #datacenter traffic. #CiscoGCI http://t.co/z43TuYDws7 http://t.co/gyOe7qQ95n #Cloud","source":"\u003ca href="http://twitter.com/download/iphone" rel="nofollow"\u003eTwitter for iPhone\u003c/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":809092,"id_str":"809092","name":"Mark Yolton","screen_name":"MarkYolton","location":"\u00dcT: 37.3920047,-122.1468241","profile_location":null,"description":"VP Digital (web, social, mobile, video) at Cisco. Views are mine, not necessarily my employer's. Also: husband, dad, Captain, bro ... http://t.co/mTPHBPPB8g","url":"http://t.co/mTPHBPPB8g","entities":{"url":{"urls":[{"url":"http://t.co/mTPHBPPB8g","expanded_url":"http://about.me/markyolton","display_url":"about.me/markyolton","indices":[0,22]}]},"description":{"urls":[{"url":"http://t.co/mTPHBPPB8g","expanded_url":"http://about.me/markyolton","display_url":"about.me/markyolton","indices":[134,156]}]}},"protected":false,"followers_count":7577,"friends_count":1317,"listed_count":456,"created_at":"Sat Mar 03 22:34:51 +0000 2007","favourites_count":471,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11041,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"022330","profile_background_image_url":"http://pbs.twimg.com/profile_background_images/743498470/bd46012fd7157d5260cd1be994f250e0.jpeg","profile_background_image_url_https":"https://pbs.twimg.com/profile_background_images/743498470/bd46012fd7157d5260cd1be994f250e0.jpeg","profile_background_tile":false,"profile_image_url":"http://pbs.twimg.com/profile_images/378800000478983905/a7c469f9cea14cf932a221442bfda29b_normal.jpeg","profile_image_url_https":"https://pbs.twimg.com/profile_images/378800000478983905/a7c469f9cea14cf932a221442bfda29b_normal.jpeg","profile_banner_url":"https://pbs.twimg.com/profile_banners/809092/1389471588","profile_link_color":"0084B4","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"C0DFEC","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":{"type":"Point","coordinates":[37.43316324,-121.89547864]},"coordinates":{"type":"Point","coordinates":[-121.89547864,37.43316324]},"place":{"id":"6ef29a7e78ca38a5","url":"https://api.twitter.com/1.1/geo/id/6ef29a7e78ca38a5.json","place_type":"city","name":"Milpitas","full_name":"Milpitas, CA","country_code":"US","country":"United States","contained_within":[],"bounding_box":{"type":"Polygon","coordinates":[[[-121.931305,37.39609],[-121.861066,37.39609],[-121.861066,37.466856],[-121.931305,37.466856]]]},"attributes":{}},"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"datacenter","indices":[23,34]},{"text":"CiscoGCI","indices":[44,53]},{"text":"Cloud","indices":[100,106]}],"symbols":[],"user_mentions":[],"urls":[{"url":"http://t.co/z43TuYDws7","expanded_url":"http://cs.co/6013v6SB","display_url":"cs.co/6013v6SB","indices":[54,76]}],"media":[{"id":545237749906014208,"id_str":"545237749906014208","indices":[77,99],"media_url":"http://pbs.twimg.com/media/B5ES2EFIAAAt0rj.png","media_url_https":"https://pbs.twimg.com/media/B5ES2EFIAAAt0rj.png","url":"http://t.co/gyOe7qQ95n","display_url":"pic.twitter.com/gyOe7qQ95n","expanded_url":"http://twitter.com/CiscoSP360/status/545237750300311552/photo/1","type":"photo","sizes":{"medium":{"w":600,"h":598,"resize":"fit"},"small":{"w":340,"h":339,"resize":"fit"},"large":{"w":846,"h":844,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"}},"source_status_id":545237750300311552,"source_status_id_str":"545237750300311552","source_user_id":14616081,"source_user_id_str":"14616081"}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"metadata":{"iso_language_code":"en","result_type":"recent"},"created_at":"Thu Dec 11 05:14:34 +0000 2014","id":542910291139248129,"id_str":"542910291139248129","text":"Good thing about being a datacenter nerd: I have several ups batteries laying around. #hellastorm","source":"\u003ca href="http://twitter.com/download/iphone" rel="nofollow"\u003eTwitter for iPhone\u003c/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":17216994,"id_str":"17216994","name":"Andrew","screen_name":"AndrewKuhlmann","location":"North Oakland // SF","profile_location":null,"description":"Robot Commander @piston, dad of a human cat. Opinions are like, my opinions, man.","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":53,"friends_count":160,"listed_count":0,"created_at":"Thu Nov 06 19:12:12 +0000 2008","favourites_count":34,"utc_offset":-28800,"time_zone":"Tijuana","geo_enabled":true,"verified":false,"statuses_count":511,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"131516","profile_background_image_url":"http://abs.twimg.com/images/themes/theme14/bg.gif","profile_background_image_url_https":"https://abs.twimg.com/images/themes/theme14/bg.gif","profile_background_tile":true,"profile_image_url":"http://pbs.twimg.com/profile_images/541750475008122880/0NFt-3Gq_normal.jpeg","profile_image_url_https":"https://pbs.twimg.com/profile_images/541750475008122880/0NFt-3Gq_normal.jpeg","profile_banner_url":"https://pbs.twimg.com/profile_banners/17216994/1417848103","profile_link_color":"009999","profile_sidebar_border_color":"EEEEEE","profile_sidebar_fill_color":"EFEFEF","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":{"type":"Point","coordinates":[37.85049224,-122.25722061]},"coordinates":{"type":"Point","coordinates":[-122.25722061,37.85049224]},"place":{"id":"ab2f2fac83aa388d","url":"https://api.twitter.com/1.1/geo/id/ab2f2fac83aa388d.json","place_type":"city","name":"Oakland","full_name":"Oakland, CA","country_code":"US","country":"United States","contained_within":[],"bounding_box":{"type":"Polygon","coordinates":[[[-122.34266,37.699279],[-122.114711,37.699279],[-122.114711,37.8847092],[-122.34266,37.8847092]]]},"attributes":{}},"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"hellastorm","indices":[86,97]}],"symbols":[],"user_mentions":[],"urls":[]},"favorited":false,"retweeted":false,"lang":"en"}],"search_metadata":{"completed_in":0.089,"max_id":545335269185294337,"max_id_str":"545335269185294337","query":"%22backup+software%22+OR+%22disaster+recovery%22+OR+datacenter","refresh_url":"?since_id=545335269185294337&q=%22backup%20software%22%20OR%20%22disaster%20recovery%22%20OR%20datacenter&geocode=37.7749%2C-122.4194%2C100mi&lang=en&result_type=recent&include_entities=1","count":15,"since_id":0,"since_id_str":"0"}}

`twurl accounts` throws errors

I was unable to use accounts, so I ran gem uninstall twurl and then gem install twurl, getting 0.9.3. I made sure all my other gems were updated. I authorized my Twitter account, and can post to it from the command line. But when I type twurl accounts, I still get the following:

/Users/emeyer/.rvm/gems/ruby-2.1.1/gems/twurl-0.9.3/lib/twurl/account_information_controller.rb:11:in `sort': comparison of NilClass with String failed (ArgumentError)
	from /Users/emeyer/.rvm/gems/ruby-2.1.1/gems/twurl-0.9.3/lib/twurl/account_information_controller.rb:11:in `dispatch'
	from /Users/emeyer/.rvm/gems/ruby-2.1.1/gems/twurl-0.9.3/lib/twurl/abstract_command_controller.rb:7:in `dispatch'
	from /Users/emeyer/.rvm/gems/ruby-2.1.1/gems/twurl-0.9.3/lib/twurl/cli.rb:38:in `dispatch'
	from /Users/emeyer/.rvm/gems/ruby-2.1.1/gems/twurl-0.9.3/lib/twurl/cli.rb:21:in `run'
	from /Users/emeyer/.rvm/gems/ruby-2.1.1/gems/twurl-0.9.3/bin/twurl:4:in `<top (required)>'
	from /Users/emeyer/.rvm/gems/ruby-2.1.1/bin/twurl:23:in `load'
	from /Users/emeyer/.rvm/gems/ruby-2.1.1/bin/twurl:23:in `<main>'
	from /Users/emeyer/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
	from /Users/emeyer/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'

:AbstractCommandController (NameError)

After installing twurl on ubuntu 8.0.4 I am getting the error when running any twurl command

/usr/lib/ruby/gems/1.8/gems/twurl-0.6.1/bin/../lib/twurl/configuration_controller.rb:2: uninitialized constant Twurl::AbstractCommandController (NameError)

Any Ideas How to resolve this?

Save authentification and load at next twurl request

Hi,

I'm pretty new to twurl and Ruby and I'm wondering if �there's a way to "save" the authentification so that I don't have to re-enter my consumer key/secret and obtain a PIN everytime I restart twurl?

Thanks!

Uninitialized constant error, with fix

On some systems, running twurl can can cause the error:

rory@ubuntu:~/Documents/twurl$ ./bin/twurl
/home/rory/Documents/twurl/lib/twurl/request_controller.rb:2:in `<module:Twurl>':uninitialized constant Twurl::AbstractCommandController (NameError)

This smells like a file isn't being loaded, so looking at twurl.rb, the culprit is this:

library_files = Dir[File.join(File.dirname(__FILE__), "/twurl/**/*.rb")]
library_files.each do |file|
    require file
end

The reason this is a problem is the Dir[] construction doesn't guarantee any sort of order as it relies on the OS for ordering. We can see this by changing it to:

library_files = Dir[File.join(File.dirname(__FILE__), "/twurl/**/*.rb")]
puts "The first file loaded is: " + library_files.first
exit

Which outputs (on my system)
The first file loaded is: /home/rory/Documents/twurl/lib/twurl/request_controller.rb

Since request_controller subclasses AbstractCommandController, it fails because that file hasn't been loaded yet. There's two ways out of this: either specifying the requires by hand in order or setting up autoloads. (Rails dances around the issue by messing with autoload and using ActiveSupport for class symbol -> file name mapping)

I fixed this in my fork using autoloads and sent a pull request.

Running Gems

Hi,

This isn't your problem, but nothing else I've tried has come back with any help, so before I tear my hair completely out perhaps you could point me in the right direction.

Blindly following instructions I have installed oauth and twurl gems, this tells me so:

l$ gem list --local

*** LOCAL GEMS ***

oauth (0.4.2)
twurl (0.6.1)

But any attempt to run these on the command line gives the following results:

$ oauth
No command 'oauth' found, did you mean: blah blah blah

$ twurl
twurl: command not found

Now I'm sure there is something humiliatingly obvious that I've missed, as I say, just a pointer in the right direction is all I need.

Hamish.

How to POST file contents

I have a file that contains:

$ cat targeting.txt 
[{"operation_type":"Create","params":{"line_item_id":"6f9an","targeting_type":"LOCATION","targeting_value":"5122804691e5fecc"}},{"operation_type":"Delete","params":{"targeting_criterion_id":"b60b9z"}}]

I'd like to send the file contents in a POST request. I've tried various approaches, such as:

$ twurl -H ads-api.twitter.com -X POST -A "Content-Type: application/json" -d "@targeting.txt" "/1/batch/accounts/18ce54d4x5t/targeting_criteria" | jq
{
  "errors": [
    {
      "code": "INVALID",
      "message": "The JSON string format is invalid"
    }
  ],
  "request": [],
  "operation_errors": []
}

I've also tried -f targeting.txt but get 415 Unsupported Media Type error.

However, if I include the actual data in the request, it succeeds.

$ twurl -H ads-api.twitter.com -X POST -A "Content-Type: application/json" -d '[{"operation_type":"Create","params":{"line_item_id":"6f9an","targeting_type":"LOCATION","targeting_value":"5122804691e5fecc"}},{"operation_type":"Delete","params":{"targeting_criterion_id":"b60b9z"}}]' "/1/batch/accounts/18ce54d4x5t/targeting_criteria" | jq
{
  "data_type": "targeting_criterion",
  "data": [
    {
      "line_item_id": "6f9an",
      "name": "San Francisco-Oakland-San Jose CA, US",
      "id": "al7vt2",
      "location_type": "CITY",
      "operator_type": "EQ",
      "created_at": "2016-11-11T22:59:50Z",
      "targeting_value": "5122804691e5fecc",
      "updated_at": "2016-12-23T01:27:18Z",
      "deleted": false,
      "targeting_type": "LOCATION"
    },
    {
      "line_item_id": "6f9an",
      "name": "api",
      "id": "b60b9z",
      "operator_type": "EQ",
      "created_at": "2016-12-23T01:07:40Z",
      "targeting_value": "api",
      "updated_at": "2016-12-23T01:27:18Z",
      "deleted": true,
      "targeting_type": "BROAD_KEYWORD"
    }
  ],
  "request": [
    {
      "params": {
        "line_item_id": "6f9an",
        "targeting_type": "LOCATION",
        "targeting_value": "5122804691e5fecc",
        "account_id": "18ce54d4x5t"
      },
      "operation_type": "Create"
    },
    {
      "params": {
        "targeting_criterion_id": "b60b9z",
        "account_id": "18ce54d4x5t"
      },
      "operation_type": "Delete"
    }
  ]
}

Any thoughts?

cc: @tushdante, @jbabichjapan.

"Media type unrecognized"

The error is described in this issue #58
but the title of that issue is misleading as it was originally just a call for help.

I tested on Ruby 2.1.6 and 2.3.0, as well as Twurl 0.9.2 and 0.9.3 with 100% the same results.
I tried various ways of (un)decorating the file, without any luck. I can however post status updates no problem, so my entire Authentication as well as software setup seems to work.

Here's the output:

twurl -H upload.twitter.com "/1.1/media/upload.json" -f "image.jpg" -F media -X POST -t
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.5.1\r\nContent-Type: multipart/form-data, boundary=\"00Twurl341955148568111164lruwT99\"\r\nAuthorization: OAuth oauth_body_hash=\"bhshYF0Iz3AschkQrzW3TEAfZV0%3D\", oauth_consumer_key=\"iEOlZD5Kh4HG633EftGPYFeJs\", oauth_nonce=\"5dxaVwtkmAm3QReXBtuV6IwEOoR5TLffJ6RHRoO0\", oauth_signature=\"xz%2BZqJSKaP9mA%2B%2FSBOuyCR8VgmA%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1468695682\", oauth_token=\"754363975098331137-r7rxJkjIkCtq3sL4VuEqWOwdvvKprS1\", oauth_version=\"1.0\"\r\nConnection: close\r\nHost: upload.twitter.com\r\nContent-Length: 227\r\n\r\n"
<- "--00Twurl341955148568111164lruwT99\r\nContent-Disposition: form-data; name=\"media\"; filename=\"image.jpg\"\r\nContent-Type: application/octet-stream\r\n\r\n\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x01\x00\xA8\x00\xA8\x00\x00\xFF\xE1\x00fExif\x00\x00MM\x00*\x00\x00\x00\b\x00\x04\x01\r\n--00Twurl341955148568111164lruwT99--\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, 16 Jul 2016 19:01:25 GMT\r\n"
-> "expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
-> "last-modified: Sat, 16 Jul 2016 19:01:25 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%3A146869568503599049; Domain=.twitter.com; Path=/; Expires=Mon, 16-Jul-2018 19:01:25 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: c84ca3f7b0337ec48d0b086c256d34d9\r\n"
-> "x-frame-options: SAMEORIGIN\r\n"
-> "x-rate-limit-limit: 415\r\n"
-> "x-rate-limit-remaining: 407\r\n"
-> "x-rate-limit-reset: 1468698804\r\n"
-> "x-response-time: 35\r\n"
-> "x-transaction: 00506adc008c5941\r\n"
-> "x-tsa-request-body-time: 10\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\xAA\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

undefined method <=> for :x_auth_username:Symbol

Here is a mostly complete stack trace...

/Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/helper.rb:37:in `<=>': undefined method `<=>' for :x_auth_username:Symbol (NoMethodError)
    from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/helper.rb:37:in `sort'
    from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/helper.rb:37:in `normalize'
    from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/consumer.rb:359:in `create_http_request'
    from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/consumer.rb:187:in `create_signed_request'
    from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/consumer.rb:159:in `request'
    from /Library/Ruby/Gems/1.8/gems/oauth-0.4.7/lib/oauth/consumer.rb:194:in `token_request'
    from /Library/Ruby/Gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/oauth_client.rb:85:in `exchange_credentials_for_access_token'
    from /Library/Ruby/Gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/authorization_controller.rb:6:in `dispatch'
    from /Library/Ruby/Gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/abstract_command_controller.rb:7:in `dispatch'
    from /Library/Ruby/Gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/cli.rb:31:in `dispatch'
    from /Library/Ruby/Gems/1.8/gems/twurl-0.7.0/bin/../lib/twurl/cli.rb:14:in `run'
    from /Library/Ruby/Gems/1.8/gems/twurl-0.7.0/bin/twurl:4
    from /usr/bin/twurl:19:in `load'
    from /usr/bin/twurl:19

I fixed this locally by changing Twurl::OAuthClient#client_auth_parameters to return strings instead of symbols...

    def client_auth_parameters
      {'x_auth_username' => username, 'x_auth_password' => password, 'x_auth_mode' => 'client_auth'}
    end

Maybe this is a OAuth issue?

Issue using authorize on Windows 7

When using authorize with a consumer key and a secret key, i ran into an issue

C:\Users\Graeme>twurl authorize --consumer-key "{a key}" \ --consumer-secret "{another key}"
Go to {a url} and paste in the supplied PIN
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/twurl-0.9.3/lib/twurl/oauth_client.rb:138:in 'perform_pin_authorize_workflow': private method 'gets' called for Twurl::CLI:Class (NoMethodError)
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/twurl-0.9.3/lib/twurl/oauth_client.rb:125:in 'rescue in exchange_credentials_for_access_token'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/twurl-0.9.3/lib/twurl/oauth_client.rb:122:in 'exchange_credentials_for_access_token'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/twurl-0.9.3/lib/twurl/authorization_controller.rb:6:in 'dispatch'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/twurl-0.9.3/lib/twurl/abstract_command_controller.rb:7:in 'dispatch'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/twurl-0.9.3/lib/twurl/cli.rb:38:in 'dispatch'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/twurl-0.9.3/lib/twurl/cli.rb:21:in 'run'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/twurl-0.9.3/bin/twurl:4:in '<top (required)>'
from C:/Ruby22-x64/bin/twurl:23:in 'load'
from C:/Ruby22-x64/bin/twurl:23:in '

'

I managed to fix it by replacing
pin = gets
on line 138 of oauth_client.rb with
pin = $stdin.gets
though I'm not sure if this change would break in other environments.
I'm new to contributing to open-source software, so I apologize in advance if i should have simply forked and created a pull request, or if this is otherwise the wrong place.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.