根据Twitter documentation。有3种状态对象(推文,转发和引文推文)。
我正在根据推文ID搜索相关的推文,发现有些情况下retweeted_status(用于标识Retweets)和quoted_status(用于标识Quote Tweets)都丢失了。
所以想知道这些Tweet对象代表什么。
代码段:
#Imports
import tweepy
import pandas as pd
import json
#Variables that contains the user credentials to access Twitter API
access_token = ACCESS_TOKEN
access_token_secret = ACCESS_TOKEN_SECRET
consumer_key = CONSUMER_KEY
consumer_secret = CONSUMER_SECRET
#Authenticate Twitter API
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
#Entity refers to person or thing who's tweets we are interested in
entity = api.get_user('realDonaldTrump')
#Get recent status/tweet of entity
set_result = api.user_timeline(id=entity.id, count=1)
# tweet is a tweepy.models.Status object
# https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/tweet-object
tweet = set_result[0]
#Fetch related tweets
related_tweets = []
for status in tweepy.Cursor(api.search,
q=tweet.id_str,
#lang='en',
tweet_mode='extended').items(500):
related_tweets.append(status)
tweetdf = pd.DataFrame()
#Build the dataframe with key information
...
tweetdf['retweeted'] = list(map(
lambda tweet: int(hasattr(tweet,'retweeted_status')),
related_tweets))
tweetdf['quoted'] = list(map(
lambda tweet: int(hasattr(tweet,'quoted_status')),
related_tweets))
print(len(tweetdf[(tweetdf["retweeted"] == 0) & (tweetdf["quoted"] == 0)]))