From: Suhem Parack Date: Tue, 1 Mar 2022 16:47:22 +0000 (-0800) Subject: Added more examples for Twitter API v2 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8a0e6e50503856f62a41adda13225331cf596803;p=tweepy.git Added more examples for Twitter API v2 --- diff --git a/examples/API_v2/get_liked_tweets.py b/examples/API_v2/get_liked_tweets.py new file mode 100644 index 0000000..8bd33a7 --- /dev/null +++ b/examples/API_v2/get_liked_tweets.py @@ -0,0 +1,19 @@ +import tweepy + + +# Replace bearer token value with your own +bearer_token = "" + +# Initializing the Tweepy client +client = tweepy.Client(bearer_token) + +# Replace User ID +id = '2244994945' + +# By default the Tweet ID and Tweet text are returned. If you want additional fields, use the appropriate +# fields and expansions +tweets = client.get_liked_tweets(id=id, tweet_fields=['context_annotations','created_at']) + +for tweet in tweets.data: + print(tweet) + \ No newline at end of file diff --git a/examples/API_v2/get_liking_users.py b/examples/API_v2/get_liking_users.py new file mode 100644 index 0000000..32cb6aa --- /dev/null +++ b/examples/API_v2/get_liking_users.py @@ -0,0 +1,19 @@ +import tweepy + + +# Replace bearer token value with your own +bearer_token = "" + +# Initializing the Tweepy client +client = tweepy.Client(bearer_token) + +# Replace Tweet ID +id = '1441054496931541004' + +# By default the user ID, name and username are returned. user_fields can be used +# to specify the additional user data that you want returned for each user e.g. profile_image_url +users = client.get_liking_users(id=id, user_fields=['profile_image_url']) + +for user in users.data: + print(user) + \ No newline at end of file diff --git a/examples/API_v2/get_retweeters.py b/examples/API_v2/get_retweeters.py new file mode 100644 index 0000000..57a654a --- /dev/null +++ b/examples/API_v2/get_retweeters.py @@ -0,0 +1,19 @@ +import tweepy + + +# Replace bearer token value with your own +bearer_token = "" + +# Initializing the Tweepy client +client = tweepy.Client(bearer_token) + +# Replace Tweet ID +id = '1441054496931541004' + +# By default the user ID, name and username are returned. user_fields can be used +# to specify the additional user data that you want returned for each user e.g. profile_image_url +users = client.get_retweeters(id=id, user_fields=['profile_image_url']) + +for user in users.data: + print(user) + \ No newline at end of file diff --git a/examples/API_v2/get_users_followers.py b/examples/API_v2/get_users_followers.py new file mode 100644 index 0000000..9150825 --- /dev/null +++ b/examples/API_v2/get_users_followers.py @@ -0,0 +1,19 @@ +import tweepy + + +# Replace bearer token value with your own +bearer_token = "" + +# Initializing the Tweepy client +client = tweepy.Client(bearer_token) + +# Replace user ID +id = '2244994945' + +# By default the user ID, name and username are returned. user_fields can be used +# to specify the additional user data that you want returned for each user e.g. profile_image_url +users = client.get_users_followers(id=id, user_fields=['profile_image_url']) + +for user in users.data: + print(user.id) + \ No newline at end of file diff --git a/examples/API_v2/get_users_mentions.py b/examples/API_v2/get_users_mentions.py new file mode 100644 index 0000000..ff3af52 --- /dev/null +++ b/examples/API_v2/get_users_mentions.py @@ -0,0 +1,19 @@ +import tweepy + + +# Replace bearer token value with your own +bearer_token = "" + +# Initializing the Tweepy client +client = tweepy.Client(bearer_token) + +# Replace user ID +id = '2244994945' + +# By default the Tweet ID and Tweet text will be returned. If you want additional data, +# specify it used fields and expansions +tweets = client.get_users_mentions(id=id) + +for tweet in tweets.data: + print(tweet) + \ No newline at end of file diff --git a/examples/API_v2/get_users_timeline.py b/examples/API_v2/get_users_timeline.py new file mode 100644 index 0000000..48865a2 --- /dev/null +++ b/examples/API_v2/get_users_timeline.py @@ -0,0 +1,19 @@ +import tweepy + + +# Replace bearer token value with your own +bearer_token = "" + +# Initializing the Tweepy client +client = tweepy.Client(bearer_token) + +# Replace user ID +id = '2244994945' + +# By default the Tweet ID and Tweet text will be returned. If you want additional data, +# specify it used fields and expansions +tweets = client.get_users_tweets(id=id) + +for tweet in tweets.data: + print(tweet) + \ No newline at end of file diff --git a/examples/API_v2/lookup_tweets_using_tweet_ids.py b/examples/API_v2/lookup_tweets_using_tweet_ids.py new file mode 100644 index 0000000..a11e202 --- /dev/null +++ b/examples/API_v2/lookup_tweets_using_tweet_ids.py @@ -0,0 +1,19 @@ +import tweepy + + +# Replace bearer token value with your own +bearer_token = "" + +# Initializing the Tweepy client +client = tweepy.Client(bearer_token) + +# Replace Tweet IDs +ids = ['1409935014725177344', '1409931481552543749', '1441054496931541004'] + +# By default the Tweet ID and Tweet text are returned. If you want additional fields, use the appropriate +# fields and expansions +tweets = client.get_tweets(ids=ids, tweet_fields=['context_annotations','created_at','geo']) + +for tweet in tweets.data: + print(tweet) + \ No newline at end of file diff --git a/examples/API_v2/lookup_users_using_user_ids.py b/examples/API_v2/lookup_users_using_user_ids.py new file mode 100644 index 0000000..2ed6743 --- /dev/null +++ b/examples/API_v2/lookup_users_using_user_ids.py @@ -0,0 +1,19 @@ +import tweepy + + +# Replace bearer token value with your own +bearer_token = "" + +# Initializing the Tweepy client +client = tweepy.Client(bearer_token) + +# Replace User IDs +ids = ['2244994945'] + +# By default the user ID, name and username are returned. user_fields can be used +# to specify the additional user data that you want returned for each user e.g. profile_image_url +users = client.get_users(ids=ids, user_fields=['profile_image_url']) + +for user in users.data: + print(user.profile_image_url) + \ No newline at end of file diff --git a/examples/API_v2/recent_tweets_count.py b/examples/API_v2/recent_tweets_count.py new file mode 100644 index 0000000..630b713 --- /dev/null +++ b/examples/API_v2/recent_tweets_count.py @@ -0,0 +1,18 @@ +import tweepy + + +# Replace bearer token value with your own +bearer_token = "" + +# Initializing the Tweepy client +client = tweepy.Client(bearer_token) + +# Replace with your own search query +query = 'covid -is:retweet' + +# Granularity can be day, hour or minute +counts = client.get_recent_tweets_count(query=query, granularity='day') + +for count in counts.data: + print(count) + \ No newline at end of file