File: linkedin.rst

package info (click to toggle)
python-requests-oauthlib 1.3.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 460 kB
  • sloc: python: 1,984; makefile: 159
file content (39 lines) | stat: -rw-r--r-- 1,655 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
LinkedIn OAuth 2 Tutorial
=========================

Setup credentials following the instructions on `LinkedIn`_.  When you
have obtained a ``client_id`` and a ``client_secret`` you can try out the
command line interactive example below.

.. _`LinkedIn`: https://www.linkedin.com/secure/developer

.. code-block:: pycon

    >>> # Credentials you get from registering a new application
    >>> client_id = '<the id you get from linkedin>'
    >>> client_secret = '<the secret you get from linkedin>'

    >>> # OAuth endpoints given in the LinkedIn API documentation
    >>> authorization_base_url = 'https://www.linkedin.com/uas/oauth2/authorization'
    >>> token_url = 'https://www.linkedin.com/uas/oauth2/accessToken'

    >>> from requests_oauthlib import OAuth2Session
    >>> from requests_oauthlib.compliance_fixes import linkedin_compliance_fix

    >>> linkedin = OAuth2Session(client_id, redirect_uri='http://127.0.0.1')
    >>> linkedin = linkedin_compliance_fix(linkedin)

    >>> # Redirect user to LinkedIn for authorization
    >>> authorization_url, state = linkedin.authorization_url(authorization_base_url)
    >>> print 'Please go here and authorize,', authorization_url

    >>> # Get the authorization verifier code from the callback url
    >>> redirect_response = raw_input('Paste the full redirect URL here:')

    >>> # Fetch the access token
    >>> linkedin.fetch_token(token_url, client_secret=client_secret,
    ...                      authorization_response=redirect_response)

    >>> # Fetch a protected resource, i.e. user profile
    >>> r = linkedin.get('https://api.linkedin.com/v1/people/~')
    >>> print r.content