Skip to content

Instantly share code, notes, and snippets.

@140am
Created January 23, 2014 06:24
Show Gist options
  • Save 140am/8573840 to your computer and use it in GitHub Desktop.
Save 140am/8573840 to your computer and use it in GitHub Desktop.
Example of using the Python Tumblr API v2 Client
""" Tumblr API Example - Python CLI
"""
import oauth2
import urlparse
import pytumblr
REQUEST_TOKEN_URL = 'http://www.tumblr.com/oauth/request_token'
AUTHORIZATION_URL = 'http://www.tumblr.com/oauth/authorize'
ACCESS_TOKEN_URL = 'http://www.tumblr.com/oauth/access_token'
CONSUMER_KEY = 'SECRET_CONSUMER_KEY'
CONSUMER_SECRET = 'SECRET_CONSUMER_SECRET'
consumer = oauth2.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
client = oauth2.Client(consumer)
resp, content = client.request(REQUEST_TOKEN_URL, "GET")
request_token = dict(urlparse.parse_qsl(content))
OAUTH_TOKEN = request_token['oauth_token']
OAUTH_TOKEN_SECRET = request_token['oauth_token_secret']
print "Request Token:"
print " - oauth_token = %s" % OAUTH_TOKEN
print " - oauth_token_secret = %s" % OAUTH_TOKEN_SECRET
client = pytumblr.TumblrRestClient(
CONSUMER_KEY,
CONSUMER_SECRET,
OAUTH_TOKEN,
OAUTH_TOKEN_SECRET
)
// number of posts
client.blog_info('userX')['blog']['posts']
client.posts('userX', offset=0, limit=10)
@adaam
Copy link

adaam commented Jul 29, 2016

Very useful example.
Thanks.

@140am
Copy link
Author

140am commented Aug 12, 2016

glad it helped 🙇 - i based https://github.com/140am/tumblrproxy on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment