如何以tweepy(而非t.co链接)打印完整的网址?以下代码打印出“这是一个测试链接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
答案 0 :(得分:9)
不确定如何使用tweepy,但您希望将include_entities
设置为True,而Twitter API将包含带有响应的t.co
网址的完整网址。
可能类似于:
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']