新手程序员在这里寻求帮助。我有一个标签列表,我想从中获取从 01-01-2015 到 31-12-2018 的所有历史推文。
我尝试使用 Tweepy 库,但它只允许访问最近 7 天的推文。我还尝试使用 GetOldTweets,因为它可以访问历史推文,但它不断崩溃。所以现在我获得了 Twitter 的高级 API 访问权限,这也让我可以访问完整的历史推文。
为了使用高级 API 进行查询,我不能使用 Tweepy 库(因为它没有与高级 API 的链接,对吗?),我的选择是 TwitterAPI 和 Search-Tweets。
1- TwitterAPI 和 Search-Tweets 是否提供有关用户名、用户位置、用户是否经过验证、推文的语言、推文的来源、转发和收藏的计数以及每条推文的日期的信息?(就像 tweepy 一样)。我找不到有关此的任何信息。
2- 我可以在查询中提供时间跨度吗?
3-我该如何做这一切?
这是我的 Tweepy 库代码:
hashtags = ["#AAPL","#FB","#KO","#ABT","#PEPCO",...]
df = pd.DataFrame(columns = ["Hashtag", "Tweets", "User", "User_Followers",
"User_Location", "User_Verified", "User_Lang", "User_Status",
"User_Method", "Fav_Count", "RT_Count", "Tweet_date"])
def tweepy_df(df,tags):
for cash in tags:
i = len(df)+1
for tweet in tweepy.Cursor(api.search, q= cash, since = "2015-01-01", until = "2018-12-31").items():
print(i, end = '\r')
df.loc[i, "Hashtag"] = cash
df.loc[i, "Tweets"] = tweet.text
df.loc[i, "User"] = tweet.user.name
df.loc[i, "User_Followers"] = tweet.followers_count
df.loc[i, "User_Location"] = tweet.user.location
df.loc[i, "User_Verified"] = tweet.user.verified
df.loc[i, "User_Lang"] = tweet.lang
df.loc[i, "User_Status"] = tweet.user.statuses_count
df.loc[i, "User_Method"] = tweet.source
df.loc[i, "Fav_Count"] = tweet.favorite_count
df.loc[i, "RT_Count"] = tweet.retweet_count
df.loc[i, "Tweet_date"] = tweet.created_at
i+=1
return df
例如,我如何适应 Twitter API 库?
我知道它应该适应这样的事情:
for tweet in api.request('search/tweets', {'q':cash})
但它仍然缺少所需的时间跨度。而且我不确定特征的名称是否与该库的名称匹配。