我已成功将LinkedIn登录与Python集成在一起。根据我们的要求,它需要获得的字段远远多于r_liteProfile
。因此,我可以访问r_basicProfile
并请求检索数据。
这是代码:
response_fullFields = requests.get("https://api.linkedin.com/v2/me?projection=(id,first-name,last-name)", headers={'Authorization': 'Bearer ' + accessToken })
但是它仅返回配置文件“ id”。即使我使用以下方式访问它:
response_fullFields = requests.get("https://api.linkedin.com/v2/me?projection=(id,first-name,last-name,maiden-name,headline,location,industry)", headers={'Authorization': 'Bearer ' + accessToken })
结果相同。
在我的开发人员应用中,我已设置权限:
r_emailaddress
3-legged member permission
r_liteprofile
3-legged member permission
w_member_social
3-legged member permission
我正在努力解决这个问题。谁能帮助我解决这个问题。
答案 0 :(得分:0)
这是检索配置文件数据。
import requests
import json
rty = " https://api.linkedin.com/v2/me"
details = requests.get(rty, headers={'Authorization': 'Bearer ' + accesstoken })
response = json.loads(details.content.decode("utf-8"))
first_name = response["localizedFirstName"]
last_name = response["localizedLastName"]
profile_picture = response["profilePicture"]["displayImage"]
另一种简化的方式
我只是浏览数据并提取了字段。
rty = "https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))"
details = requests.get(rty, headers={'Authorization': 'Bearer ' + accesstoken })
response = json.loads(details.content.decode("utf-8"))
first_name = response["firstName"]["localized"]["en_US"]
last_name = response["lastName"]["localized"]["en_US"]
profile_url = response["profilePicture"]["displayImage~"]["elements"][0]["identifiers"][0]["identifier"]
也做了一些挖掘来获取电子邮件地址。这是一种方法
email_url = "https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))"
email_details = requests.get(email_url, headers={'Authorization': 'Bearer ' + accesstoken })
email_response = json.loads(email_details.content.decode("utf-8"))
email_address = email_response["elements"][0]["handle~"]["emailAddress"]
希望这会有所帮助。干杯