我正在尝试使用 Python 访问 LinkedIn API,我已经能够成功获取访问令牌并使用
application
库实例化一个 linkedin
对象。
# Set up LinkedIn API credentials and scope
LINKEDIN_CLIENT_ID = "myappclientid"
LINKEDIN_CLIENT_SECRET = "myappclientsecret"
REDIRECT_URI = 'https://localhost:8000'
SCOPE = ['r_emailaddress', 'r_liteprofile', 'w_member_social']
# Create LinkedInAuthentication object with credentials and scope
authentication = linkedin.LinkedInAuthentication(
LINKEDIN_CLIENT_ID,
LINKEDIN_CLIENT_SECRET,
REDIRECT_URI,
SCOPE
)
# Get the authorization URL to prompt user to grant access
authorization_url = authentication.authorization_url
print(authorization_url)
# User should visit the URL and be redirected to a localhost URL with a 'code' parameter
response_url = input("Please enter the redirected URL:")
parsed_url = urlparse(response_url)
query_params = parse_qs(parsed_url.query)
code_param = query_params.get('code', [None])[0]
# Set authorization code in the authentication object to retrieve access token
authentication.authorization_code = code_param
access_token = authentication.get_access_token()
print("Access token:", access_token[0])
# Create LinkedInApplication object with access token
application = linkedin.LinkedInApplication(token=access_token[0])
# Try to get the user's profile with the LinkedInApplication object
try:
application.get_profile()
except Exception as e:
print("Error: ", e)
但是,当我尝试使用任何 LinkedInApplication 方法时,出现以下错误:
Traceback (most recent call last): File
"/usr/local/lib/python3.10/site-packages/requests/models.py", line
971, in json
return complexjson.loads(self.text, **kwargs) File "/usr/local/Cellar/[email protected]/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py",
line 346, in loads
return _default_decoder.decode(s) File "/usr/local/Cellar/[email protected]/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py",
line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/Cellar/[email protected]/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py",
line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char
0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"/usr/local/lib/python3.10/site-packages/linkedin/utils.py", line 56,
in raise_for_error
任何人都可以帮助我了解导致此错误的原因以及如何修复它以便我可以访问 LinkedIn API 吗?