Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit e7925a9

Browse files
committed
ongoing work on readme's doc
1 parent 8f12936 commit e7925a9

1 file changed

Lines changed: 46 additions & 47 deletions

File tree

README

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,21 @@ Python Twitter Tools
44
[![Tests](https://github.com/python-twitter-tools/twitter/workflows/Tests/badge.svg)](https://github.com/python-twitter-tools/twitter/actions)
55
[![Coverage Status](https://coveralls.io/repos/github/python-twitter-tools/twitter/badge.svg?branch=master)](https://coveralls.io/github/python-twitter-tools/twitter?branch=master)
66

7-
The Minimalist Twitter API for Python is a Python API for Twitter,
8-
everyone's favorite Web 2.0 Facebook-style status updater for people
9-
on the go.
10-
11-
Also included is a Twitter command-line tool for getting your friends'
12-
tweets and setting your own tweet from the safety and security of your
13-
favorite shell and an IRC bot that can announce Twitter updates to an
14-
IRC channel.
7+
The Minimalist Twitter API for Python is a Python port for [Twitter's API](https://developer.twitter.com/en/docs/api-reference-index).
158

169
For more information:
1710

1811
* install the [package](https://pypi.org/project/twitter/) `pip install twitter`
1912
* import the `twitter` package and run `help()` on it
20-
* run `twitter -h` for command-line tool help
21-
22-
twitter - The Command-Line Tool
23-
-------------------------------
24-
25-
The command-line tool lets you do some awesome things:
26-
27-
* view your tweets, recent replies, and tweets in lists
28-
* view the public timeline
29-
* follow and unfollow (leave) friends
30-
* various output formats for tweet information
31-
32-
The bottom line: type `twitter`, receive tweets.
33-
34-
twitterbot - The IRC Bot
35-
------------------------
36-
37-
The IRC bot is associated with a Twitter account (either your own account or an
38-
account you create for the bot). The bot announces all tweets from friends
39-
it is following. It can be made to follow or leave friends through IRC /msg
40-
commands.
41-
42-
43-
`twitter-log`
44-
-------------
45-
46-
`twitter-log` is a simple command-line tool that dumps all public
47-
tweets from a given user in a simple text format. It is useful to get
48-
a complete offsite backup of all your tweets. Run `twitter-log` and
49-
read the instructions.
50-
51-
`twitter-archiver` and `twitter-follow`
52-
---------------------------------------
53-
54-
twitter-archiver will log all the tweets posted by any user since they
55-
started posting. twitter-follow will print a list of all of all the
56-
followers of a user (or all the users that user follows).
5713

5814

5915
Programming with the Twitter API classes
6016
========================================
6117

6218
The `Twitter` and `TwitterStream` classes are the key to building your own
6319
Twitter-enabled applications.
20+
The `Twitter2` and `TwitterStream2` classes are helpers preconfigured to
21+
handle the specificities of Twitter API v2.
6422

6523

6624
The `Twitter` class
@@ -79,13 +37,54 @@ The list of most accessible functions is listed at:
7937

8038
**[https://developer.twitter.com/en/docs/api-reference-index](https://developer.twitter.com/en/docs/api-reference-index)**
8139

82-
Examples:
40+
Examples with Twitter API v2:
41+
_____________________________
8342

8443
```python
8544
from twitter import *
8645

46+
# First instantiate the class by authenticating with OAuth:
47+
t = Twitter2(
48+
auth=OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET))
49+
50+
# Or with OAuth2 using a bearer token:
51+
t = Twitter2(auth=OAuth2(bearer_token=BEARER_TOKEN))
52+
53+
# Note Twitter2 is only a wrapper for the regular Twitter class with presets,
54+
# so the above are equivalent to the following:
8755
t = Twitter(
88-
auth=OAuth(token, token_secret, consumer_key, consumer_secret))
56+
auth=OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET),
57+
api_version="2",
58+
format="")
59+
t = Twitter(auth=OAuth2(bearer_token=BEARER_TOKEN), api_version="2", format="")
60+
61+
# Then use it to query the API. For instance grab a specific tweet:
62+
t.tweets(id=1293595870563381249)
63+
64+
# Twitter v2 API does not return automatically all fields like v1.1 was
65+
# One needs to specify which expansions and fields are desired as listed in
66+
# the [official documentation](https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id).
67+
# For instance, to get everything available on the previous tweet:
68+
t.tweets(
69+
id=1293595870563381249,
70+
expansions="author_id,referenced_tweets.id,referenced_tweets.id.author_id,entities.mentions.username,attachments.poll_ids,attachments.media_keys,in_reply_to_user_id,geo.place_id",
71+
params={
72+
"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",
73+
"user.fields": "created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld",
74+
"media.fields": "duration_ms,height,media_key,preview_image_url,type,url,width,public_metrics",
75+
"place.fields": "contained_within,country,country_code,full_name,geo,id,name,place_type",
76+
"poll.fields": "duration_minutes,end_datetime,id,options,voting_status"
77+
})
78+
79+
```
80+
81+
Examples with Twitter API Standard v1.1:
82+
________________________________________
83+
84+
```python
85+
from twitter import *
86+
87+
t = Twitter(auth=OAuth(token, token_secret, consumer_key, consumer_secret))
8988

9089
# Get your "home" timeline
9190
t.statuses.home_timeline()

0 commit comments

Comments
 (0)