以下是我的代码。
用Python V3编写
import tweepy
consumer_key="***"
consumer_secret="***"
access_key="***"
access_secret="***"
TweetCollection={}
def get_all_tweets(screen_name):
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
alltweets = api.user_timeline(screen_name = screen_name, count = 20, include_entities = True)
for tweet in alltweets:
Id=tweet.id_str
PublishedAt=str(tweet.created_at)
Tweet=unescape(tweet.text)
ScreenName=screen_name
if tweet.entities['urls']!=[]:
StoryUrl=tweet.entities['urls'][0].get('url')
else:
StoryUrl=None
if Id is not None:
TweetCollection[Id]={'Tweet': Tweet, 'ScreenName': ScreenName, 'StoryUrl': StoryUrl, 'PublishedAt': PublishedAt}
get_all_tweets('SportIndustry')
print(TweetCollection={})
我需要" t.co/PNMCqmC9Nw"但我得到" t.co /PQwP3WoSGL"
为什么呢?以及如何纠正这个问题?
答案 0 :(得分:1)
我通过更改参数找到了一种方法。
alltweets = api.user_timeline(screen_name = screen_name, count = 20, include_entities = True, tweet_mode='extended')
以及
Tweet=unescape(tweet.full_text)