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

Add v2 API examples in README? #181

Open
cmdcolin opened this issue Aug 22, 2022 · 8 comments
Open

Add v2 API examples in README? #181

cmdcolin opened this issue Aug 22, 2022 · 8 comments

Comments

@cmdcolin
Copy link

I was just trying to use the examples in the README but they appeared to need an elevated access

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

{"errors":[{"message":"You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve","code":453}]}"

I could try to apply for this but having v2 API examples available may be useful

@manzt
Copy link

manzt commented Sep 11, 2022

Yes, just ran into this with https://github.com/manzt/cron-tweet...

Not sure if twurl supports the authentication that v2 requires.

@cmdcolin
Copy link
Author

cmdcolin commented Sep 11, 2022

I am not very knowledgeable about authentication but I wrote a short article writing a nodejs twitter client that posts tweets (with media). interestingly the media upload is a v1 api and the posting is a v2 api, they said they are working on a v2 media upload api on their forums but it is fine to mix and match them in this case). I did not have to apply for any elevated access to twitter using this approach!

short article here
https://cmdcolin.github.io/posts/2022-08-26-twitterbot

@manzt
Copy link

manzt commented Sep 11, 2022

Thanks for sharing. I also wrote something in deno today which seems to work for the v2 endpoint: https://gist.github.com/manzt/d6cbf7f901a6e7b68c145d3820fbed7b

@manzt
Copy link

manzt commented Sep 11, 2022

Ok I figured it out!

twurl /2/tweets \
	--data '{"text": "Testing twurl"}' \
	--header 'Content-Type: application/json' \
	--consumer-key $TWITTER_API_KEY \
	--consumer-secret $TWITTER_API_SECRET \
	--access-token $TWITTER_ACCESS_TOKEN \
	--token-secret $TWITTER_ACCESS_TOKEN_SECRET

You need the content-type header in this syntax to avoid twurl url-form-encoding the data by default (like for v1.1 APIs).

@andypiper
Copy link
Contributor

Legacy OAuth 1.0A authentication continues to work with twurl for now, and so it will work for the v2 endpoints that can support authentication without granular scopes. For now, that does include the v2 Tweet create endpoint.

At the moment, twurl does not support OAuth 2 user authentication (with PKCE) and there is nobody actively working on adding this. This means that you cannot use twurl with (for example) the new Bookmarks endpoints, as these require specific OAuth 2.0 scopes that provide access to bookmarks data.

Over time, I would expect OAuth 1.0A to be phased out, and we prefer OAuth 2.0 for new apps (although at the current time unfortunately, the media upload functionality still uses the legacy flow).

I appreciate that this is not an ideal situation at the moment!

If anyone would like to fork twurl to work on the new authentication scheme, feel free to do so; otherwise I anticipate that it will gradually be sunset over time as v2 comes to the fore.

@manzt
Copy link

manzt commented Sep 12, 2022

Thanks for the clarification! I'm afraid I'm not knowledgeable enough about authentication to take this on at the moment.

@lukepighetti
Copy link

@andypiper is there an alternative to twurl which can be used with the v2 api? If not, the Twitch CLI is good inspiration for what I'm hoping to find

@ElfQrin
Copy link

ElfQrin commented Aug 27, 2023

twurl /2/tweets --data '{"text": "Testing twurl"}' --header 'Content-Type: application/json' --consumer-key $TWITTER_API_KEY --consumer-secret $TWITTER_API_SECRET --access-token $TWITTER_ACCESS_TOKEN --token-secret $TWITTER_ACCESS_TOKEN_SECRET

returns

You must authorize first.

If I add the bearer token

twurl /2/tweets --data '{"text": "Testing twurl"}' --header 'Content-Type: application/json' --consumer-key $TWITTER_API_KEY --consumer-secret $TWITTER_API_SECRET --access-token $TWITTER_ACCESS_TOKEN --token-secret $TWITTER_ACCESS_TOKEN_SECRET --bearer $TWITTER_ACCESS_BEARER

returns

/var/lib/gems/3.1.0/gems/twurl-0.9.7/lib/twurl/oauth_client.rb:81:in load_client_for_non_profile_app_only_auth': undefined method to_hash' for nil:NilClass (NoMethodError)

        'bearer_token' => rcfile.bearer_tokens.to_hash[options.consumer_key]
                                              ^^^^^^^^
    from /var/lib/gems/3.1.0/gems/twurl-0.9.7/lib/twurl/oauth_client.rb:15:in `load_from_options'
    from /var/lib/gems/3.1.0/gems/twurl-0.9.7/lib/twurl/cli.rb:23:in `dispatch'
    from /var/lib/gems/3.1.0/gems/twurl-0.9.7/lib/twurl/cli.rb:19:in `run'
    from /var/lib/gems/3.1.0/gems/twurl-0.9.7/bin/twurl:4:in `<top (required)>'
    from /usr/local/bin/twurl:25:in `load'
    from /usr/local/bin/twurl:25:in `<main>'

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

5 participants