Updating a LinkedIn Status with a PUT request (using LinkedIn Profile API, Django, Python)
As part of a recent project, we were asked to set up a system that allowed folks to authenticate using their LinkedIn credentials.
We used LinkedIn's Oauth Authentication API, and plugged it into Django's built-in user admin using django-socialauth.
I'm writing this short guide because the Internet seems woefully disorganized & underinformed on this topic.
So, let's get rolling. Here are some assumptions:
- You are pretty familiar with Python, Django, and the depths of joy that these things bring
- You've installed django-socialauth
- You're already authenticating via Oauth, and logging-in visitors
(if you want more information about this process from a higher level, just ask!)
Here are some other things to be aware of:
- I designed this view to operate as an AJAX endpoint, where a status update is POSTed to the url (re: request.POST['msg'])
- The request.session['access_token'] is something I added in when the django login occurs.
- This requires python-oauth2, which had a dependency on the httplib
- We have procured a LinkedIn API key and secret from LinkedIn. We set them in settings.py
Here's my view:
I got a variety of interesting errors during development. Here are some of them, and what the problem was:
401 not authorized
I was using the wrong key & secret when creating my token
400 message too long
There's a 140 character limit on the statuses, so.. yea. That happened.
Are you running into a weird error? Put it in the comments, and I'll see what I can do to help.
If you enjoyed this post, then tweet about it!