Twitter bio and profile picture url

260 views
Skip to first unread message

Ollie Glass

unread,
May 21, 2012, 4:11:04 PM5/21/12
to django-so...@googlegroups.com
Hello,

is there an example of how to capture a user's Twitter bio and profile picture url? I can't see how to do this in the docs.

Thanks,

Ollie

Matías Aguirre

unread,
May 21, 2012, 4:22:12 PM5/21/12
to django-social-auth
This is the API you should call to gather that data:

https://dev.twitter.com/docs/api/1/get/users/lookup

I usually use urlopen/json but there are a few python libraries to get the API
data too.

Matías

Excerpts from Ollie Glass's message of 2012-05-21 17:11:04 -0300:
--
Matías Aguirre (matias...@gmail.com)

Ollie Glass

unread,
May 21, 2012, 4:29:48 PM5/21/12
to django-so...@googlegroups.com
Thanks for your help, Matias. Here's my solution so far. I've adjusted the Facebook backend example to save Twitter data, like so:


class UserProfile(models.Model):
# This field is required.
user = models.OneToOneField(User)

# Other fields here
twitter = models.TextField(blank=True)

def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

from social_auth.signals import pre_update
from social_auth.backends.twitter import TwitterBackend

def twitter_extra_values(sender, user, response, details, **kwargs):
user_profile = user.get_profile()
user_profile.twitter = json.dumps(response)
user_profile.save()
return True

pre_update.connect(twitter_extra_values, sender=TwitterBackend)



In the twitter json, the profile_image_url and description fields have the image and bio.
Reply all
Reply to author
Forward
0 new messages