How to update profile Image?


#1

Using : python 2.7 , Django 1.7 python-oauth2

image_post = "https://api.twitter.com/1.1/statuses/update.json?status=FirstTestFrom"
resp, content = client.request(image_post, "POST")

You know what i can see my status in Twitter ( So it’s working but … )

image_post = "https://api.twitter.com/1.1/account/update_profile_image.json?image={}".format(encodedImage)
resp, content = client.request(image_post, "POST")

Now i’m getting error

Could not authenticate you

#2

Hi there!

I’m not 100% at first glance, but I’m not sure adding URL parameters on the image_post will work. You likely need to include encodedImage as POST request parameters.

The python-twitter project on github serves a similar purpose, and performs a file upload (search for UploadImage). It even performs the Base64 encoding for you.

FWIW,I use this project regularly, and I might suggest using it yourself.


#3

Also, since you mentioned it was on Django, I added sample code that uses the python-twitter code base to show an profile image upload example. You can see it here:

The basic pieces you need are in this commit:

My example is loosely based on the following documentation:

https://docs.djangoproject.com/en/1.7/topics/http/file-uploads/

Thanks, and let us know if you have other questions. (And pull requests greatly appreciated!)