I have reduced to tweepy, and I'm wandering about how you can track and save the image that the user posts on his tweets. I found several ways in the tutorials to get custom tweets, but I could not find a way to filter only images.
I use the following code to get custom tweets. How can I get only custom images?
EDIT: I am editing my code as shown above:
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(OAUTH_TOKEN, OAUTH_SECRET)
api = tweepy.API(auth)
timeline = api.user_timeline(count=10, screen_name = "zenitiss")
for tweet in timeline:
for media in tweet.entities.get("media",[{}]):
print media
#checks if there is any media-entity
if media.get("type",None) == "photo":
# checks if the entity is of the type "photo"
image_content=requests.get(media["media_url"])
print image_content
However, the for loop seems to not work. A print line prints a null object. Basically, when I try to print user urls like karyperry, I get:
{u'url': u'http://t.co/TaP2JZrpxu', u'indices': [42, 64], u'expanded_url':
u'http://youtu.be/7bDLIV96LD4', u'display_url': u'youtu.be/7bDLIV96LD4'}
{u'url': u'https://t.co/t3hv7VQiPG', u'indices': [42, 65], u'expanded_url':
u'https://vine.co/v/MgvxZA2qKbV', u'display_url': u'vine.co/v/MgvxZA2qKbV'}
{u'url': u'http://t.co/vnJAAU7KN6', u'indices': [50, 72], u'expanded_url':
u'http://instagram.com/p/n01XZjv-fp/', u'display_url': u'instagram.com/p/n01XZjv-fp/'}
{u'url': u'http://t.co/NycqAwtcgo', u'indices': [78, 100], u'expanded_url':
u'http://bit.ly/1o7xQRj', u'display_url': u'bit.ly/1o7xQRj'}
{u'url': u'http://t.co/BG6ozuRD6D', u'indices': [111, 133], u'expanded_url':
u'http://www.johnnywujek.com/sos', u'display_url': u'johnnywujek.com/sos'}
{u'url': u'http://t.co/nWIQ9ruJ3f', u'indices': [88, 110], u'expanded_url':
u'http://uncf.us/1kSXIwF', u'display_url': u'uncf.us/1kSXIwF'}
{u'url': u'http://t.co/yTbOgqt9fw', u'indices': [101, 123], u'expanded_url':
u'http://instagram.com/p/nvxD8eP-SZ/', u'display_url': u'instagram.com/p/nvxD8eP-SZ/'}
URL- , , "url" "media" tweet.entities.get( "url", [{}]). - URL- .