@@ -9,31 +9,41 @@ command line interactive example below.
9
9
10
10
.. code-block :: pycon
11
11
12
+ >>> # Imports
13
+ >>> import os
14
+ >>> from requests_oauthlib import OAuth2Session
15
+
16
+ >>> # Set environment variables
17
+ >>> os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
18
+
12
19
>>> # Credentials you get from registering a new application
13
20
>>> client_id = '<the id you get from linkedin>'
14
21
>>> client_secret = '<the secret you get from linkedin>'
15
22
16
- >>> # OAuth endpoints given in the LinkedIn API documentation
17
- >>> authorization_base_url = 'https://www.linkedin.com/uas/oauth2/authorization'
18
- >>> token_url = 'https://www.linkedin.com/uas/oauth2/accessToken'
23
+ >>> # LinkedIn OAuth2 requests require scope and redirect_url parameters.
24
+ >>> # Ensure these values match the auth values in your LinkedIn App
25
+ >>> # (see auth tab on LinkedIn Developer page)
26
+ >>> scope = ['r_liteprofile']
27
+ >>> redirect_url = 'http://127.0.0.1'
19
28
20
- >>> from requests_oauthlib import OAuth2Session
21
- >>> from requests_oauthlib.compliance_fixes import linkedin_compliance_fix
29
+ >>> # OAuth endpoints given in the LinkedIn API documentation
30
+ >>> authorization_base_url = 'https://www.linkedin.com/oauth/v2/authorization'
31
+ >>> token_url = 'https://www.linkedin.com/oauth/v2/accessToken'
22
32
23
- >>> linkedin = OAuth2Session(client_id, redirect_uri='http://127.0.0.1')
24
- >>> linkedin = linkedin_compliance_fix(linkedin)
33
+ >>> linkedin = OAuth2Session(client_id, redirect_uri='http://127.0.0.1', scope=scope)
25
34
26
35
>>> # Redirect user to LinkedIn for authorization
27
36
>>> authorization_url, state = linkedin.authorization_url(authorization_base_url)
28
- >>> print ' Please go here and authorize,', authorization_url
37
+ >>> print(f" Please go here and authorize: { authorization_url}")
29
38
30
39
>>> # Get the authorization verifier code from the callback url
31
- >>> redirect_response = raw_input ('Paste the full redirect URL here:')
40
+ >>> redirect_response = input ('Paste the full redirect URL here:')
32
41
33
42
>>> # Fetch the access token
34
43
>>> linkedin.fetch_token(token_url, client_secret=client_secret,
44
+ ... include_client_id=True,
35
45
... authorization_response=redirect_response)
36
46
37
47
>>> # Fetch a protected resource, i.e. user profile
38
- >>> r = linkedin.get('https://api.linkedin.com/v1/people/~ ')
39
- >>> print r.content
48
+ >>> r = linkedin.get('https://api.linkedin.com/v2/me ')
49
+ >>> print( r.content)
0 commit comments