How to get Twitter banner image using API?

164 Views Asked by At

I want to check the existence of the Twitter banner image by using Twython. The banner image can be retrieved by profile_banner_url but if the user doesn't have a banner image this parameter does not exist in the API call and the output will be as follows. So the following print is not executed.

from twython import Twython
APP_KEY = consumer_key
APP_SECRET = consumer_secret
OAUTH_TOKEN = access_token
OAUTH_TOKEN_SECRET = access_token_secret

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
user_info = twitter.show_user(screen_name='USER_SCREEN_NAME')

if user_info['profile_banner_url'] == 'profile_banner_url':  # IF THERE IS NO BANNER
    print('No Banner Image')  # NOT EXECUTED

Output:

profile_banner_url

Any alternative solutions beside using Twython are also welcome.

0

There are 0 best solutions below