File: tweet_fields.py

package info (click to toggle)
tweepy 4.12.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,488 kB
  • sloc: python: 6,042; makefile: 16; javascript: 10
file content (24 lines) | stat: -rw-r--r-- 639 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import tweepy


bearer_token = ""

client = tweepy.Client(bearer_token)

# You can specify additional Tweet fields to retrieve using tweet_fields
response = client.search_recent_tweets(
    "Tweepy", tweet_fields=["created_at", "lang"]
)
tweets = response.data

# You can then access those fields as attributes of the Tweet objects
for tweet in tweets:
    print(tweet.id, tweet.lang)

# Alternatively, you can also access fields as keys, like a dictionary
for tweet in tweets:
    print(tweet["id"], tweet["lang"])

# There’s also a data attribute/key that provides the entire data dictionary
for tweet in tweets:
    print(tweet.data)