ozgur / python-linkedin

Python interface to the LinkedIn API
http://ozgur.github.com/python-linkedin/
MIT License
889 stars 394 forks source link

JSON Error with get_access_token() #40

Open C6silver opened 10 years ago

C6silver commented 10 years ago

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 commented 10 years ago

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)

Michelcyc commented 10 years ago

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?

C6silver commented 10 years ago

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.