Tweety - 我没有在Twitter上分享Url,而是获得了推文链接?

时间:2017-10-26 15:06:02

标签: python api twitter tweepy

以下是我的代码。

用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"

为什么呢?以及如何纠正这个问题?

1 个答案:

答案 0 :(得分:1)

我通过更改参数找到了一种方法。

alltweets = api.user_timeline(screen_name = screen_name, count = 20, include_entities = True, tweet_mode='extended')

以及

Tweet=unescape(tweet.full_text)