如何用tweepy打印完整的url ?

时间:2021-06-02 07:35:48

How do I print out the full urls in tweepy (rather than the t.co link)? The following code prints out "this is a test link http://t.co/93Hme7Jv 90210", even though twitter.com shows "this is a test link http://www.test.com/test 90210".

如何用tweepy(而不是t)打印完整的url ?公司链接)?下面的代码输出“这是一个测试链接http://t”。co/93Hme7Jv 90210”,尽管twitter.com显示“这是一个测试链接http://www.test.com/test 90210”。

import tweepy, random

consumer_key="my_key"
consumer_secret="my_secret"
access_token="my_access"
access_token_secret="my_token"

rand = random.randint(1,999999999)

if __name__ == '__main__':
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    status = tweepy.API(auth)
    tweepy.API(auth).update_status('this is a test link http://www.test.com/test %s' % (rand))
    user = 'test_user'
    for status in tweepy.Cursor(status.user_timeline, id=user).items(20): 
        print status.text

1 个解决方案

#1


8  

Not sure how that'd work with tweepy, but you want to set include_entities to True, and the Twitter API will include the full URLs of t.co URLs with responses.

不知道在tweepy上如何工作,但是您希望将include_entities设置为True,而Twitter API将包含t的完整url。公司网址与反应。

Probably something like:

可能类似:

for status in tweepy.Cursor(status.user_timeline, id=user, include_entities=True).items(20): 
    for url in status.entities['urls']:
         print url['expanded_url']

#1


8  

Not sure how that'd work with tweepy, but you want to set include_entities to True, and the Twitter API will include the full URLs of t.co URLs with responses.

不知道在tweepy上如何工作,但是您希望将include_entities设置为True,而Twitter API将包含t的完整url。公司网址与反应。

Probably something like:

可能类似:

for status in tweepy.Cursor(status.user_timeline, id=user, include_entities=True).items(20): 
    for url in status.entities['urls']:
         print url['expanded_url']