Need help with OAuth data request

8 posts / 0 new
Last post
Bob Ralian's picture
Joined: 2010-12-06
Jan 25, 2011
Need help with OAuth data request

I'm able to get all my tokens and all appears to be working, but when I try to get info from the people api, I get an unauthorized response. I've pored over all the docs I could find (including the zero-to-hero slideshow from Taylor Singletary: http://www.slideshare.net/episod/linkedin-oauth-zero-to-hero) and I can't seem to find what I'm doing wrong.I'm working on this locally on the dev_server of a google app engine python application using the webapp framework.Here's the request I'm sending (from the debug console):Making HTTP request: host = api.linkedin.com, url = https://api.linkedin.com/v1/people/~?oauth_nonce=3228209849670894546&oauth_timestamp=1295992693&oauth_consumer_key=v0B8v4vPtW1H9d_Z38UuArsR1iCXdlBxflF4c-K8Oeqwor2LtvJNldRe3uMqKu_7&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_token=b03477a7-f974-4d50-8630-590367ea5d15&oauth_signature=7iUtT2b7mjeo3%2FhGBEw8FwJjMxI%3D, payload = None, headers = {'Host': 'api.linkedin.com', 'X-Li-Format': 'json', 'Accept-Encoding': 'gzip', 'Authorization': 'OAuth oauth_nonce="3228209849670894546", oauth_timestamp="1295992693", oauth_consumer_key="v0B8v4vPtW1H9d_Z38UuArsR1iCXdlBxflF4c-K8Oeqwor2LtvJNldRe3uMqKu_7", oauth_signature_method="HMAC-SHA1", oauth_version="1.0", oauth_token="b03477a7-f974-4d50-8630-590367ea5d15", oauth_signature="7iUtT2b7mjeo3%2FhGBEw8FwJjMxI%3D"', 'User-Agent': 'AppEngine-Google; (+http://code.google.com/appengine)'}The base string for the signature generated in this request is:GET&https%3A%2F%2Fapi.linkedin.com%2Fv1%2Fpeople%2F%7E&oauth_consumer_key%3Dv0B8v4vPtW1H9d_Z38UuArsR1iCXdlBxflF4c-K8Oeqwor2LtvJNldRe3uMqKu_7%26oauth_nonce%3D3228209849670894546%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1295992693%26oauth_token%3Db03477a7-f974-4d50-8630-590367ea5d15%26oauth_version%3D1.0The first thing I checked was Authorization header. That's in that request above but I'll break them out here so it's easier to read:'Authorization': 'OAuth oauth_nonce="3228209849670894546", oauth_timestamp="1295992693", oauth_consumer_key="v0B8v4vPtW1H9d_Z38UuArsR1iCXdlBxflF4c-K8Oeqwor2LtvJNldRe3uMqKu_7", oauth_signature_method="HMAC-SHA1", oauth_version="1.0", oauth_token="b03477a7-f974-4d50-8630-590367ea5d15", oauth_signature="7iUtT2b7mjeo3%2FhGBEw8FwJjMxI%3D"'Also I am building the signing key by concatenating the url-escaped consumer-secret and auth-token-secret with an ampersand in the middle as the docs show. So all of that seems correct to me (and my computer's clock is correct as well), but here's the response I get from this request:{u'status': 401, u'timestamp': 1295992693380L, u'message': u'[unauthorized]. OAU:v0B8v4vPtW1H9d_Z38UuArsR1iCXdlBxflF4c-K8Oeqwor2LtvJNldRe3uMqKu_7|b03477a7-f974-4d50-8630-590367ea5d15|*01|*01:1295992693:7iUtT2b7mjeo3/hGBEw8FwJjMxI=', u'errorCode': 0}In case this is a factor, at the point that I get the user info response (slide 24 or Zero to Hero), I am getting a couple of additional parameters that say my auth session has already expired. That doesn't sound right, but I can't find any info about that in your docs.oauth_token=b03477a7-f974-4d50-8630-590367ea5d15&oauth_token_secret=[seems like i should hide this secret in this post :-)]&oauth_expires_in=0&oauth_authorization_expires_in=0If that's a problem I'm not sure what it indicates or what I can do about it. Can someone please help me with some direction on what to do here? I've spent a lot of time spinning wheels and would really appreciate some help getting this to work.

Kirsten Hunter's picture
Joined: 2011-06-30
Jan 25, 2011

Bob, What OAuth library are you using?  Are you using python or java?  If you give us a little more information about how you're trying to go about this we can probably point you in the right direction :-)Thanks,Kirsten

Bob Ralian's picture
Joined: 2010-12-06
Jan 25, 2011

It's google app engine python using the webapp framework. I'm using an oauth library by Mike Knapp hosted here: https://github.com/mikeknapp/AppEngine-OAuth-LibraryI've tried other libraries, but wasn't able to get them to work either. I believe many of the python oauth libraries assume a later version of python than GAE supports (which only goes to 2.5.4). So I've gotten closest with this library.I've modified this library to add a new linkedin section to the file oauth.py. I've also added the header to request json and added some code to create the Authorization header. I've created a shell in a zip file that you can just unpack and load up in googleappenginelauncher yourself to test it out. You'll need to enter your consumer-key and consumer-secret and also manually add the user-key and user-secret once you get to that step, as sessions aren't enabled in this example (add these values to sampleOAuth.py). Then run up the application and go to the homepage. You'll see a login-with-linkedin button that takes you to the linkedin auth page. Then if you accept, it takes you back and shows you your user keys. At that point the app also attempts to look up the user. If you watch the console you'll see that I'm getting a 401 unauthorized response. From what I can tell, everything is working correctly up to the point of performing the lookup on the people endpoint. The app is peppered with logging statements, so watch the console and you should be able to see all the requests as they go through.Message was edited by: Kirsten Jones - I removed the attachment as it had your consumer key and secret in it. 

Kirsten Hunter's picture
Joined: 2011-06-30
Jan 25, 2011

Bob,I'll take a look at this tomorrow and see what's up.  I was going to try to get something working with GAE anyhow, so this is a reasonable place to start.  Off the top of my head I'm suspecting a signature issue, but I can verify that by running it myself.Thanks,Kirsten

Kirsten Hunter's picture
Joined: 2011-06-30
Jan 26, 2011

Hi Bob,I wasn't able to get oauth working with the library you were using - I suspect that there's something wonky about the way it is creating signatures.I'll add this to the reference documentation when it gets up there, but here's the complete answer.First, use the oauth you get with easy_install - it works with older pythons and also with GAE.Next, you need to change your oauth getting code to be like this:

    consumer = oauth.OAuthConsumer(application_key, application_secret)    accessToken = oauth.OAuthToken(user_token, user_secret)        profile_url = "http://api.linkedin.com/v1/people/~"        oauthRequest = oauth.OAuthRequest.from_consumer_and_token(                                      consumer,                                    http_url=profile_url,                                    parameters=None,                                    token=accessToken)      oauthRequest.sign_request(                                    oauth.OAuthSignatureMethod_HMAC_SHA1(),                                     consumer,                                     accessToken)       result = fetch(oauthRequest.to_url(),deadline=10)            self.response.out.write("<a href='/'>start over</a><br /><br />")      return self.response.out.write(result.content)

This is working on my GAE test application.  Let me know if you have any issues.Thanks,Kirsten

Kirsten Hunter's picture
Joined: 2011-06-30
Jan 27, 2011

I wrote up a post on how to get GAE working with LinkedIn: Integrating LinkedIn with Google App Engine (Python)Comments, feedback always welcome :-)

Sin Ly's picture
Joined: 2012-11-11
Nov 24, 2012

When you click that link, it says you can use something that is attached to that page. But you wont see anything.

Joseph DeMaria, Ph.D.'s picture
Joined: 2013-04-16
Jun 2, 2013

How can I add a slideshow component as company banner image?