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".
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
If we want to get the complete text, pass another parameter tweet_mode = "extended" . From this object, fetch the text attribute present in it. If we want to get the complete text, fetch the attribute full_text.
If you need more than 100 Tweets, you have to use the paginator method and specify the limit i.e. the total number of Tweets that you want. Replace limit=1000 with the maximum number of tweets you want. Replace the limit=1000 with the maximum number of tweets you want (gist).
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.
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With