Created
August 15, 2013 02:04
-
-
Save elidickinson/6237607 to your computer and use it in GitHub Desktop.
Update twitter profile background image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
import tempfile | |
import urllib | |
from time import sleep | |
import os | |
url = 'http://wwc.instacam.com/instacamimg/KDCA/KDCA_l.jpg' | |
# The consumer keys can be found on your application's Details | |
# page located at https://dev.twitter.com/apps (under "OAuth settings") | |
auth = tweepy.OAuthHandler(os.environ.get('CONSUMER_KEY'), os.environ.get('CONSUMER_SECRET')) | |
# The access tokens can be found on your applications's Details | |
# page located at https://dev.twitter.com/apps (located | |
# under "Your access token") | |
auth.set_access_token(os.environ.get('ACCESS_TOKEN'), os.environ.get('ACCESS_SECRET')) | |
api = tweepy.API(auth) | |
try: | |
(filename, headers) = urllib.urlretrieve(url) | |
for attempt in range(10): | |
try: | |
# The update profile API randomly throws error 131 like half the time | |
api.update_profile_background_image(filename, use=1, tile=0) | |
except tweepy.error.TweepError as err: | |
if err[0][0]['code'] == 131: | |
print "attempt %d, resulted in %s" % (attempt, err) | |
sleep(1) | |
continue | |
else: | |
raise | |
break | |
finally: | |
os.remove(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! You should use
update_profile_banner
instead ofupdate_profile_background_image
because the latter is deprecated!