python-twitter-tools / twitter

Python Twitter API
http://mike.verdone.ca/twitter/
MIT License
3.17k stars 710 forks source link

support for Twitter API v2 #433

Closed glyph closed 2 years ago

glyph commented 3 years ago

It's still in early access but it would be nice to get the jump on it: https://developer.twitter.com/en/docs/twitter-api/early-access

boogheta commented 3 years ago

Hello @glyph The work has been initiated towards this and it should come in a next release. In the mean time you can already use it by checking out the "api_v2" branch and calling it for instance like this:

t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET, KEY, SECRET), api_version="2", format="")
tweets = t.tweets(ids="1293595870563381249", expansions='attachments.poll_ids,attachments.media_keys,author_id,entities.mentions.username,geo.place_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id', params={"media.fields": 'duration_ms,height,media_key,preview_image_url,type,url,width,public_metrics', "place.fields": 'contained_within,country,country_code,full_name,geo,id,name,place_type', "poll.fields": 'duration_minutes,end_datetime,id,options,voting_status', "tweet.fields": 'attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,public_metrics,possibly_sensitive,referenced_tweets,reply_settings,source,text,withheld', "user.fields": 'created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld'})                                                                                                                                                                                                 

Currently the syntax of the new expansions and xxx.fields arguments are not really practical with the way this lib calls arguments, so this might change by the time it's released in order to simplify this a little.

glyph commented 3 years ago

Thanks for the information! I'm not in a rush, I just didn't see a ticket already tracking this; glad to hear that work is already underway.

glyph commented 2 years ago

Today I did pipx install 'git+https://github.com/python-twitter-tools/twitter@api_v2' and all my tweets still get truncated at 140 characters, even though the branch has had activity as recently as February of this year. Any idea what's going on there?

RouxRC commented 2 years ago

What routes of which API did you use?

glyph commented 2 years ago

I typed twitter at a command-line.

boogheta commented 2 years ago

That's normal then, the command line tools of the lib are not maintained anymore.