Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
API.update_profile_background_image()
The update_profile_background_image()
method of the API
class in Tweepy module is used to update the profile background image of the authenticated user.
Syntax : API.update_profile_background_image(filename)
Parameter :
- filename : the local path to the image file.
Returns : an object of class User
Example 1 : Update the background picture with the following picture :
# import the module import tweepy # assign the values accordingly consumer_key = "" consumer_secret = "" access_token = "" access_token_secret = "" # authorization of consumer key and consumer secret auth = tweepy.OAuthHandler(consumer_key, consumer_secret) # set access to user's access key and access secret auth.set_access_token(access_token, access_token_secret) # calling the api api = tweepy.API(auth) # the file path filename = "sunflower-field.jpg" # updating the background picture api.update_profile_background_image(filename) |
Output :
Example 2 : Trying to upload a file other than GIF, JPG, or PNG will create an exception.
# the file path filename = "sunflower-field.mp3" # updating the profile picture api.update_profile_image(filename) |
Output :
raise TweepError('Invalid file type for image: %s' % file_type) tweepy.error.TweepError: Invalid file type for image: None
<!–
–>
Please Login to comment…