DEKHTIARJonathan / python3-linkedin

Python3 interface to the LinkedIn API
https://dekhtiarjonathan.github.io/python3-linkedin/
MIT License
84 stars 36 forks source link

invalid redirect_uri #2

Closed alceal closed 7 years ago

alceal commented 7 years ago

I have tried authenticating with OAuth 2.0 according to the instructions but I always get this error. Could anyone help me?

DEKHTIARJonathan commented 7 years ago

Can you please send your code and the error message? I can't help like this

alceal commented 7 years ago

I created a linkedin application and got the keys:

screen shot 2017-08-16 at 19 34 19 screen shot 2017-08-16 at 19 34 39

This is my script:


APPLICATON_KEY    = '77m******************'
APPLICATON_SECRET = '5ok******************'

RETURN_URL = 'http://localhost:8080'

authentication = linkedin.LinkedInAuthentication(APPLICATON_KEY,
                                                 APPLICATON_SECRET,
                                                 RETURN_URL,
                                                 linkedin.PERMISSIONS.enums.values())
print(authentication.authorization_url)

Then I followed the instructions:

  1. Run http_api.py
  2. Visit http://localhost:8080
  3. Visit authentication.authorization_url and I get this error:
screen shot 2017-08-16 at 19 59 49
DEKHTIARJonathan commented 7 years ago

Okay, for what I can see right here, at least two things mismatches:

You need to have exactly the same things on both sides


By the way, your permission are wrong ... You can not requests all of the possible ones (like in the demo).

For recall the followings are available via the PERMISSIONS enum, you need to match the settings and the one declared in the LinkedIn Dev Console ;)

PERMISSIONS = enum('Permission',
                   # Default Permissions
                   BASIC_PROFILE='r_basicprofile',
                   EMAIL_ADDRESS='r_emailaddress',
                   SHARE='w_share',

                   # Company Permissions
                   COMPANY_ADMIN='rw_company_admin',

                   # Permissions you need to apply to : https://help.linkedin.com/app/ask/path/api-dvr
                   FULL_PROFILE='r_fullprofile',
                   CONTACT_INFO='r_contactinfo'
 )
alceal commented 7 years ago

I've changed:

My callback URL on the LinkedIn Dev Panel = http://localhost:8080 My callback URL in the application = http://localhost:8080 My code:

from linkedin import linkedin
APPLICATON_KEY    = '77m******************'
APPLICATON_SECRET = '5ok******************'

RETURN_URL = 'http://localhost:8080'

authentication = linkedin.LinkedInAuthentication(APPLICATION_KEY,
                                                 APPLICATION_SECRET,
                                                 RETURN_URL,
                                                 permissions='r_basicprofile')

print(authentication.authorization_url)

But I got this new error:

http://localhost:8080/?error=invalid_scope&error_description=Your+application+has+not+been+authorized+for+the+scope+%22r_fullprofile%22#!

alceal commented 7 years ago

Solved:

authentication = linkedin.LinkedInAuthentication(APPLICATION_KEY,
                                                 APPLICATION_SECRET,
                                                 RETURN_URL,
                                                 permissions=['r_basicprofile'])

Permissions must be in a list.

alceal commented 7 years ago

The auth code is with &state=?

#############################################&state=########################

I've tried both options: w/ and w/o &state= but I got the same error:

Traceback (most recent call last):
  File "/Users/alceal/Dropbox/Projects/Python/.virtualenvs/linkedin-bot/lib/python3.6/site-packages/linkedin/utils.py", line 49, in raise_for_error
    response.raise_for_status()
  File "/Users/alceal/Dropbox/Projects/Python/.virtualenvs/linkedin-bot/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://www.linkedin.com/uas/oauth2/accessToken

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "linkedin-bot/linkedin-bot.py", line 19, in <module>
    result = authentication.get_access_token()
  File "/Users/alceal/Dropbox/Projects/Python/.virtualenvs/linkedin-bot/lib/python3.6/site-packages/linkedin/linkedin.py", line 136, in get_access_token
    raise_for_error(response)
  File "/Users/alceal/Dropbox/Projects/Python/.virtualenvs/linkedin-bot/lib/python3.6/site-packages/linkedin/utils.py", line 62, in raise_for_error
    raise ex(message)
linkedin.exceptions.LinkedInError: invalid_request: Unknown Error

My code:

from linkedin import linkedin
APPLICATON_KEY    = '77m******************'
APPLICATON_SECRET = '5ok******************'

RETURN_URL = 'http://localhost:8080'

authentication = linkedin.LinkedInAuthentication(APPLICATION_KEY,
                                                 APPLICATION_SECRET,
                                                 RETURN_URL,
                                                 permissions=['r_basicprofile'])

authentication.authorization_code = '********************************************'
result = authentication.get_access_token()

print ("Access Token:", result.access_token)
print ("Expires in (seconds):", result.expires_in)
DEKHTIARJonathan commented 7 years ago

Everything is explained here: https://github.com/DEKHTIARJonathan/python3-linkedin#production-authentication

Please mark the issue as solved if everything is working ;)

alceal commented 7 years ago

Sorry but it's not clear -> https://github.com/DEKHTIARJonathan/python3-linkedin#production-authentication

jayzeng commented 7 years ago

sounds like the doc needs some clarification, @alceal you should send in a pr to update the doc

alceal commented 7 years ago

@jayzeng yeah, someone should get the same result if he follows the doc but this is not the case.

DEKHTIARJonathan commented 7 years ago

It would be a great pleasure for me to merge any PR regarding the documentation ;) Feel free to fork and help @jayzeng or @alceal

Can I close this issue ?

alceal commented 7 years ago

The invalid redirect_uri issue is solved but I'm still having problems with auth code. I'll try it again later.

alceal commented 7 years ago

@DEKHTIARJonathan everything is working.