twitter / twurl

OAuth-enabled curl for the Twitter API
https://developer.twitter.com
MIT License
1.8k stars 301 forks source link

Crash on /2/users/:id/tweets #175

Closed snarfed closed 2 years ago

snarfed commented 2 years ago

Hi all! I'm starting to work with the Twitter v2 API, and I've hit a twurl crash:

$ twurl -v
0.9.6
$ twurl '/2/users/139199211/tweets?tweet.fields=attachments&author_id&conversation_id&created_at&entities&geo&id&in_reply_to_user_id&referenced_tweets&source&text'
/Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:175:in `escape': no implicit conversion of nil into String (TypeError)
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:175:in `block in escape_params'
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:174:in `each'
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:174:in `map'
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:174:in `escape_params'
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:165:in `block in extract_path!'
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:160:in `each'
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:160:in `each_with_index'
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:160:in `extract_path!'
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:108:in `parse_options'
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:17:in `run'
    from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/bin/twurl:4:in `<top (required)>'
    from /usr/local/bin/twurl:23:in `load'
    from /usr/local/bin/twurl:23:in `<main>'

I'm on macOS 12.3.1, Ruby 2.6.0.

Thanks for maintaining twurl, it's great!

andypiper commented 2 years ago

I believe the syntax should be to comma separate the tweet.fields values, but I don’t have twurl handy to run this to check right now. Can you try replacing the & with , between the names of the fields (ie. ?tweet.fields=attachments,author_id,etc…).

Also note that twurl will support app-only bearer token authentication which works with several of the v2 endpoints; but at the moment, there are no plans to add full OAuth 2.0 support with the new user authentication and granular scopes.

snarfed commented 2 years ago

Hah, true! That fixed it. Apologies, that URL was very obviously broken.

(You might still consider improving the error handling though, crashing is probably still not what you want here. 😁)