Created
March 9, 2012 20:20
-
-
Save mtwstudios/2008466 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
import urllib | |
import urlparse | |
import oauth2 as oauth | |
import httplib2 | |
httplib2.debuglevel=1 | |
consumer_key="XXXXXXXXXXXXXXXXXXXXXXXX" | |
consumer_secret="XXXXXXXXXXXXXXXXXXXXXXXX" | |
access_token_url = 'https://www.tumblr.com/oauth/access_token' | |
tumblr_username = "xxxxxxxxxxxxxxxxx" | |
tumblr_password = "xxxxxxxxxxxxxxxxx" | |
tumblr_hostname = "xxxxxxxxxxxxxxxxx.tumblr.com" | |
consumer = oauth.Consumer(consumer_key, consumer_secret) | |
client = oauth.Client(consumer) | |
client.add_credentials(tumblr_username, tumblr_password) | |
client.authorizations | |
params = {} | |
params["x_auth_username"] = tumblr_username | |
params["x_auth_password"] = tumblr_password | |
params["x_auth_mode"] = 'client_auth' | |
client.set_signature_method = oauth.SignatureMethod_HMAC_SHA1() | |
resp, token = client.request(access_token_url, method="POST",body=urllib.urlencode(params)) | |
print "======= RESPONSE TOKEN =======" | |
print resp | |
access_token = dict(urlparse.parse_qsl(token)) | |
print "======== ACCESS TOKEN ========" | |
print access_token | |
access_token = oauth.Token(access_token['oauth_token'], access_token['oauth_token_secret']) | |
client = oauth.Client(consumer, access_token) | |
print "========= USER INFO ==========" | |
print client.request("http://api.tumblr.com/v2/user/info", method="POST") | |
print "========= TEST POST ==========" | |
print client.request("http://api.tumblr.com/v2/blog/" + tumblr_hostname + "/post", method="POST", body="body=hello+from+python&type=text&title=python+entry") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment