Created
January 23, 2014 06:24
-
-
Save 140am/8573840 to your computer and use it in GitHub Desktop.
Example of using the Python Tumblr API v2 Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
glad it helped 🙇 - i based https://github.com/140am/tumblrproxy on this