LinkedIn API "Empty oauth2 access token" error
Asked Answered
A

3

6

Sorry if this is question is not suitable for stackoverflow.

I've got access token from Linkedin API. I am trying to use it however I am not sure how to include my access_token. I cannot find any example on documentation.

base_url = f'https://api.linkedin.com/v2/people?access_token={linkedin_key}&format=json'
requests.get(base_url).json()

This outputs

    {'serviceErrorCode': 65604,
 'message': 'Empty oauth2 access token',
 'status': 401}

does anyone know what's wrong? Thank you.

Almund answered 2/3, 2019 at 19:2 Comment(0)
Z
11

The access token param you need to pass is oauth2_access_token not access_token.

For example:

https://api.linkedin.com/v2/me?oauth2_access_token={linkedin_key}

I can't find it in the docs and it's been a while, but that's how I use it in my app.

Zimmermann answered 2/3, 2019 at 19:32 Comment(5)
Thank you for your help! do you know how to look at all of job posting of specific job? ex: I want to look at all job postings of the role, data scientist.Almund
That I don't know. You will have to look at their docs. I'm also afraid the jobs API may be restricted to their marketing partners.Zimmermann
any solution till yet because i am also suffering from this issue ?Equitable
Had similar problems with out of date online references and the usual vague and ambiguous API docs. This works.Depend
@ErvinKalemi from where you will get access_token?Annia
H
4

I think they want you to pass it in the headers based on my reading of their docs

https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context#step-4-make-authenticated-requests

requests.get(base_url,headers={"Authorization":"Bearer {access_token}"}).json()
Hardtack answered 2/3, 2019 at 19:11 Comment(2)
it tells me that I need to add format at the end. in such case do I add it at base_url? which will become base_url = 'api.linkedin.com/v2/people?~format=json'Almund
FWIW, when passing the same valid token via HEADER and GET at the same time I get {'serviceErrorCode': 65603, 'message': 'Multiple access token provided', 'status': 401} hinting at both types of auth being seen, at a bare minimum.Obliquity
R
-1

You shouldn't try to include it directly in header. Instead go to the Authorization tab, select OAuth2.0 and give access token there. Refer to the imageenter image description here

Rickettsia answered 18/10, 2022 at 16:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.