最近linkedin发送了一封提醒邮件:
Important update: All developers need to migrate to Version 2.0 of our APIs and OAuth 2.0 by March 1, 2019. Learn more
我正在使用 Linkedin Rest API 来获取授权后的用户信息。 旧的 v1 API 是: https://api.linkedin.com/v1/people/~
必须更改此请求。我尝试提出以下请求:
https://api.linkedin.com/v2/me
获取用户基本信息(如名字和姓氏)
然后:
https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements *(处理~))
获取用户电子邮件地址
不幸的是,第一个请求总是返回:
{
"serviceErrorCode": 100,
"message": "Not enough permissions to access: GET /me",
"status": 403
}
我在 stackoverflow 上搜索了很多,很多建议您需要作为合作伙伴订阅才能访问 v2 api
Linkedin 在迁移指南中说道:
Does my developer application have access to the v2 API? Any developer application created through the LinkedIn Developer Portal after December 15, 2018 automatically has access to the v2 API.
What about existing developer applications? If your developer application has made a successful v1 API request since October 1, 2018, your developer application automatically has access to the v2 API.
此外,如果我请求 emailAddress v2 API,我会得到正确的响应...所以我认为我不需要编译成为合作伙伴的表格。
这应该是什么问题?
这里是身份验证和 API 调用的完整路径:
1)进入auth页面请求权限
window.location.href = "https://www.linkedin.com/oauth/v2/authorization?response_type=code" +
"&client_id=" + linkedin_id + "&redirect_uri=" + redirect_uri +
"&state=" + state + "&scope=r_basicprofile+r_emailaddress"
2) 检索访问 token
request = ("https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code=" +
code + "&redirect_uri=" +
redirect_uri + "&client_id="
+ linkedin_id +
"&client_secret=" + linkedin_secret)
response = requests.get(request)
3) 检索到访问 token ,我们可以请求用户信息ALWAYS 403
headers = {"Authorization": "Bearer "+token }
get_user = requests.get('https://api.linkedin.com/v2/me', headers=headers)
4) 让 user_email 工作
get_user_email = requests.get('https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', headers=headers)
谢谢
最佳答案
如果您只需要名字和姓氏,请尝试使用 r_liteprofile
而不是 r_basicprofile
关于rest - 关于迁移到Linkedin API 2.0版本的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53834420/