File: tumblr.rst

package info (click to toggle)
python-requests-oauthlib 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 496 kB
  • sloc: python: 2,000; makefile: 159
file content (37 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download | duplicates (3)
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
Tumblr OAuth1 Tutorial
======================

Register a new application on the `tumblr application page`_.
Enter a call back url (can just be http://www.tumblr.com/dashboard) and get the ``OAuth Consumer Key`` and ``Secret Key``.

.. _`tumblr application page`: http://www.tumblr.com/oauth/apps

.. code-block:: pycon

    >>> # Credentials from the application page
    >>> key = '<the app key>'
    >>> secret = '<the app secret>'

    >>> # OAuth URLs given on the application page
    >>> request_token_url = 'http://www.tumblr.com/oauth/request_token'
    >>> authorization_base_url = 'http://www.tumblr.com/oauth/authorize'
    >>> access_token_url = 'http://www.tumblr.com/oauth/access_token'

    >>> # Fetch a request token
    >>> from requests_oauthlib import OAuth1Session
    >>> tumblr = OAuth1Session(key, client_secret=secret, callback_uri='http://www.tumblr.com/dashboard')
    >>> tumblr.fetch_request_token(request_token_url)

    >>> # Link user to authorization page
    >>> authorization_url = tumblr.authorization_url(authorization_base_url)
    >>> print 'Please go here and authorize,', authorization_url

    >>> # Get the verifier code from the URL
    >>> redirect_response = raw_input('Paste the full redirect URL here: ')
    >>> tumblr.parse_authorization_response(redirect_response)

    >>> # Fetch the access token
    >>> tumblr.fetch_access_token(access_token_url)

    >>> # Fetch a protected resource
    >>> print tumblr.get('http://api.tumblr.com/v2/user/dashboard')