Skip to content

Instantly share code, notes, and snippets.

@rvause
Created July 4, 2012 19:38
Show Gist options
  • Save rvause/3049193 to your computer and use it in GitHub Desktop.
Save rvause/3049193 to your computer and use it in GitHub Desktop.
Failed experiment trying to make an authenticated post to the theme customization url.
from flask import Flask, session, redirect, request
from tumblpy import Tumblpy
app = Flask(__name__)
app.config['SECRET_KEY'] = 'x'
consumer_key = 'x'
consumer_secret = 'x'
oauth_token = 'x'
oauth_secret = 'x'
@app.route('/')
def main():
t = Tumblpy(
app_key=consumer_key,
app_secret=consumer_secret,
oauth_token=oauth_token,
oauth_token_secret=oauth_secret
)
params = {
'id': 'x',
'user_form_key': 'x',
'name': 'x',
'title': 'x'
}
url = 'http://www.tumblr.com/customize_api/blog/x'
print t.api_request(method='POST', url=url, params=params)
@app.route('/tumblr_connect/')
def connect():
t = Tumblpy(
app_key=consumer_key,
app_secret=consumer_secret,
callback_url='x'
)
auth_props = t.get_authentication_tokens()
auth_url = auth_props['auth_url']
session['oauth_token'] = auth_props['oauth_token']
session['oauth_token_secret'] = auth_props['oauth_token_secret']
return redirect(auth_url)
@app.route('/tumblr_callback/')
def tumblr_callback():
t = Tumblpy(
app_key=consumer_key,
app_secret=consumer_secret,
oauth_token=session['oauth_token'],
oauth_token_secret=session['oauth_token_secret']
)
oauth_verifier = request.args.get('oauth_verifier', None)
authorized_tokens = t.get_access_token(oauth_verifier)
print 'oauth token: %s' % authorized_tokens['oauth_token']
print 'oauth secret: %s' % authorized_tokens['oauth_token_secret']
return 'Complete'
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment