Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print out the full url with tweepy?

Tags:

python

tweepy

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
like image 962
user_78361084 Avatar asked Aug 11 '12 19:08

user_78361084


People also ask

How do you get full text on Tweepy?

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.

How can I get more than 100 tweets on Tweepy?

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).


1 Answers

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']
like image 156
Martijn Pieters Avatar answered Oct 05 '22 07:10

Martijn Pieters