python-linkedin icon indicating copy to clipboard operation
python-linkedin copied to clipboard

JSON Error with get_access_token()

Open C6silver opened this issue 11 years ago • 3 comments

I am able to get almost to the end of the flow but I receive a: "ValueError: No JSON object could be decoded" based on the get_access_token() call.

The code: class LinkedInLogin(webapp2.RequestHandler):

def get(self):
    redirect_url ="http://127.0.0.1:14080/linkedincallback"

    authentication = linkedin.LinkedInAuthentication(api_key, api_secret, redirect_url, ["r_basicprofile","r_emailaddress"])
    self.redirect(authentication.authorization_url)

class LinkedInCallBack(webapp2.RequestHandler):

def get(self):
    redirect_url ="http://127.0.0.1:14080/linkedincallback"

    authentication = linkedin.LinkedInAuthentication(api_key, api_secret, redirect_url, ["r_basicprofile","r_emailaddress"])
    authentication.authorization_code = self.request.GET["code"]
    authentication.get_access_token()

C6silver avatar Feb 04 '14 23:02 C6silver

I've made some discoveries here that are relevant. I went ahead and coded the authentication manually without using the SDK. Interestingly when it came time to get the access token I also received a JSON error exactly as the SDK did. I examined the output which showed nothing obviously wrong. I next decided to do this in two steps by first bringing the results from the URL into a string and then I read that string via JSON and it worked. I don't know why that should have worked rather than using JSON to start. Obviously without changing the code in the SDK this does not solve the problem here and I am unsure if others are running into the same thing.

For clarity here is what I wound up writing: token = urllib2.urlopen(tokenLink).read() token2 = json.loads(token)

C6silver avatar Feb 05 '14 00:02 C6silver

I'm still a student and I'm getting the idea of the API, but I believe it uses a 2-way handshake for the authentication ( your server > API server, API server > your server ). So, the API server needs to send a message to your server, for that, your server should be online, not running locally. If you pass "http://127.0.0.1:14080/linkedincallback" as a parameter for the return URL the API server will try to redirect the call to itself and you will never get a response. Am I right?

Michelcyc avatar Jun 09 '14 13:06 Michelcyc

Michelcyc, no that isn't how it works. The browser making the login request is handed back the callback URI from the Oauth provider (LinkedIn, FaceBook, Twitter, etc.) The service itself is not calling back. The address I used in my post was indeed internal as it was for development purposes. Testing the process internally works just fine as of course I have access to that IP. In production it would be a public address.

C6silver avatar Jun 09 '14 16:06 C6silver