2
votes

I am new to Python and I would like to test the Linkedin API. I got an example of authentification code (using oauth2) from this site: https://github.com/ozgur/python-linkedin

I guess there is nothing wrong with the configuration my application on Linkedin:

ID Client : XXX

Secret client : YYY

All these box are checked: r_basicprofile, r_emailaddress, rw_company_admin, w_share

OAuth 2.0 => Authorized URL : http://localhost:8000

Here is the code:

    #-*- coding: utf-8 -*-

    from linkedin import linkedin

    API_KEY = 'XXX'
    API_SECRET = 'YYY'
    RETURN_URL = 'http://localhost:8000'
    authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL)

    print "authentication.authorization_url : " + authentication.authorization_url
    print "authentication.key : " + authentication.key
    print "authentication.secret : " + authentication.secret
    print "authentication.redirect_uri : " + authentication.redirect_uri
    print "authentication.state : " + authentication.state
    print  authentication.authorization_code
    print  authentication.token
    print  authentication._error 

    application = linkedin.LinkedInApplication(authentication)

And the result is :

authentication.authorization_url : https://www.linkedin.com/uas/oauth2/authorization?scope=&state=a2eb48d9b7b5f94a24dfbf36d498ebdc&redirect_uri=http%3A//localho st%3A8000&response_type=code&client_id=XXX

authentication.key : XXX

authentication.secret : YYY

authentication.redirect_uri : http://localhost:8000

authentication.state : a2eb48d9b7b5f94a24dfbf36d498ebdc

None

None

None

I don't understant why my authorization_code is None. According to the git hub link, redirect_url should contain the URL + the authorization code. Here I just have the URL, so I can't continue the process of authentification.

I made some research but I could'nt find anything. Does someone know what's wrong with my code or my configuration ?

Thanks!

1

1 Answers

2
votes

Well, I finally found what's wrong with this!

authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL)

This returns an URL (ex : https://www.linkedin.com/uas/oauth2/authorization?scope=r_basicprofile%20r_emailaddress&state=4a8b5b5932f182fff0a1731ebfbb05ef&redirect_uri=http%3A//localhost%3A8000&response_type=code&client_id=XXX). I had to open this URL in my browser, to log in with my Linkedin account. Then I was redirected to this URL : http://localhost%3A8000/?code=my_code&state=31624da3ad7331c11def407de0a56cc4

my_code is the code to use to get the token.

authentication.authorization_code = 'my_code'
authentication.get_access_token()

Once I got the token, I could some requests to use the API.

Hope this help.