def main(): configFile = argv[1] config = SafeConfigParser() config.read(configFile) consumer_key = config.get('consumer', 'key') consumer_secret = config.get('consumer', 'secret') tumblr = Tumblpy(consumer_key, consumer_secret) auth_props = tumblr.get_authentication_tokens() print("Go to the following link in your browser:") print(auth_props['auth_url']) print('') oauth_verifier = 'n' while oauth_verifier.lower() == 'n': oauth_verifier = raw_input('What is the PIN?: ') tumblr = Tumblpy(consumer_key, consumer_secret, auth_props['oauth_token'], auth_props['oauth_token_secret']) authorized_tokens = tumblr.get_access_token(oauth_verifier) config.set('oauth', 'key', authorized_tokens['oauth_token']) config.set('oauth', 'secret', authorized_tokens['oauth_token_secret']) print('Saving keys to config file %s' % configFile) with open(configFile, 'w') as fp: config.write(fp)
def requestToken(): # Go to http://www.tumblr.com/oauth/apps and click your # app to find out your dynamic callback url t = Tumblpy(app_key = APP_KEY, app_secret = APP_SECRET, callback_url = 'http://' + BLOG_URL) return auth_props = t.get_authentication_tokens() auth_url = auth_props['auth_url'] oauth_token = auth_props['oauth_token'] oauth_token_secret = auth_props['oauth_token_secret'] print "token: %s" % oauth_token print "token_secret: %s" % oauth_token_secret print "connect to tumblr via %s" % auth_url print "once connected obtain the value in the URL with the tag oauth_verifier" t = Tumblpy(app_key = APP_KEY, app_secret = APP_SECRET, oauth_token = oauth_token, oauth_token_secret = oauth_token_secret) oauth_verifier = raw_input("inserta el oauth verifier: ") authorized_tokens = t.get_authorized_tokens(oauth_verifier) final_oauth_token = authorized_tokens['oauth_token'] final_oauth_token_secret = authorized_tokens['oauth_token_secret'] print "token: %s" % final_oauth_token print "token_secret: %s" % final_oauth_token_secret
def authorize(): # Authorization Step 1 t = Tumblpy(app_key = app_key, app_secret = app_secret) auth_props = t.get_authentication_tokens() auth_url = auth_props['auth_url'] # temp tokens oauth_token = auth_props['oauth_token'] oauth_token_secret = auth_props['oauth_token_secret'] # Authorization Step 2 t = Tumblpy(app_key = app_key, app_secret = app_secret, oauth_token=oauth_token, oauth_token_secret=oauth_token_secret, callback_url='oob') # oauth_verifier = *Grab oauth verifier from URL* # At this point, follow instructions in commandline. print "Go to the link ", auth_url print "Click 'Allow' and when the page redirects, "\ "grab the value of oauth_verifier from the URL and enter it here." oauth_verifier = raw_input('oauth_verifier:') authorized_tokens = t.get_access_token(oauth_verifier) # Final access tokens oauth_token = authorized_tokens['oauth_token'] oauth_token_secret = authorized_tokens['oauth_token_secret'] return oauth_token, oauth_token_secret
def do_flush_key(key): spider_log.info("正在刷新Key ID:{}".format(key.id)) t = Tumblpy(key.ConsumerKey, key.ConsumerSecret) auth_props = t.get_authentication_tokens() key.Token = auth_props.get("oauth_token") key.TokenSecret = auth_props.get("oauth_token_secret") spider_log.info("请打开下面的链接执行授权") spider_log.info(auth_props.get("auth_url")) key.UpdateTime = datetime.now().strftime("%Y-%m-%d %H:%M:%S") t.client.close() session.commit() spider_log.info("刷新Key ID:{} 完成".format(key.id))
def authorize(): print("func authorize") t = Tumblpy(CONSUMER_KEY, CONSUMER_SECRET) auth_props = t.get_authentication_tokens() auth_url = auth_props['auth_url'] token = auth_props['oauth_token'] token_secret = auth_props['oauth_token_secret'] print("auth_url: ", auth_url) print("token: ", token) print("token_secret: ", token_secret)
def setup(): global oauth_token global oauth_token_secret t = Tumblpy(app_key = my_app_key, app_secret = my_app_secret, callback_url = 'http://example.com/callback/') auth_props = t.get_authentication_tokens() auth_url = auth_props['auth_url'] print auth_url oauth_token = auth_props['oauth_token'] oauth_token_secret = auth_props['oauth_token_secret']
def get_tumblpy(): keyfile = 'keys.json' keys = {} if P.exists(keyfile): print 'Using saved OAuth keys. If there is an error, remove %s' % keyfile keys = json.load(open(keyfile)) else: print 'Must complete OAuth steps first' save_keys = lambda: json.dump(keys, open(keyfile, 'w')) if not keys.get("OAUTH_CONSUMER_KEY"): print("Register an app at https://www.tumblr.com/oauth/apps .") print("Then input the given keys here.") keys['OAUTH_CONSUMER_KEY'] = raw_input("OAuth consumer key: ") keys['OAUTH_SECRET_KEY'] = raw_input("OAuth secret key: ") save_keys() if not keys.get("OAUTH_TOKEN"): t = Tumblpy(keys['OAUTH_CONSUMER_KEY'], keys['OAUTH_SECRET_KEY']) auth_props = t.get_authentication_tokens( callback_url='http://example.com/') auth_url = auth_props['auth_url'] keys['OAUTH_TOKEN_SECRET'] = auth_props['oauth_token_secret'] print 'Visit this URL: %s' % auth_url print 'Paste the redirect URL here:' redirect_url = raw_input('Redirect URL: ') res = parse_qs(redirect_url.split("?", 1)[1]) keys['OAUTH_TOKEN'] = res['oauth_token'][0].split("#")[0] keys['OAUTH_VERIFIER'] = res['oauth_verifier'][0].split("#")[0] save_keys() if not keys.get('FINAL_OAUTH_TOKEN'): t = Tumblpy(keys['OAUTH_CONSUMER_KEY'], keys['OAUTH_SECRET_KEY'], keys['OAUTH_TOKEN'], keys['OAUTH_TOKEN_SECRET']) authorized_tokens = t.get_authorized_tokens(keys['OAUTH_VERIFIER']) keys['FINAL_OAUTH_TOKEN'] = authorized_tokens['oauth_token'] keys['FINAL_OAUTH_SECRET'] = authorized_tokens['oauth_token_secret'] save_keys() print 'OAuth complete!' return Tumblpy(keys['OAUTH_CONSUMER_KEY'], keys['OAUTH_SECRET_KEY'], keys['FINAL_OAUTH_TOKEN'], keys['FINAL_OAUTH_SECRET'])
def auth(request): t = Tumblpy(app_key=settings.TUMBLR_CONSUMER_KEY, app_secret=settings.TUMBLR_SECRET_KEY) auth_props = t.get_authentication_tokens( callback_url="http://tumblrdeneme.pythonanywhere.com/callback/") auth_url = auth_props['auth_url'] oauth_token = auth_props['oauth_token'] oauth_token_secret = auth_props['oauth_token_secret'] request.session["oauth_token"] = oauth_token request.session["oauth_token_secret"] = oauth_token_secret return redirect("http://www.tumblr.com/oauth/authorize?oauth_token=%s" % oauth_token)
def GET(self): data = web.input(oauth_verifier=None) if data.oauth_verifier: tumblr = Tumblpy(app_key=KEYS['tumblr']['key'], app_secret=KEYS['tumblr']['secret'], oauth_token=session.tumblr_oauth_token, oauth_token_secret=session.tumblr_oauth_token_secret) auth = tumblr.get_authorized_tokens(data.oauth_verifier) return j({'success': True, 'auth': auth}) else: tumblr = Tumblpy(app_key=KEYS['tumblr']['key'], app_secret=KEYS['tumblr']['secret'], callback_url='https://secure.lumilux.org/admin/tumblrauth') auth = tumblr.get_authentication_tokens() auth_url = auth['auth_url'] session.tumblr_oauth_token = auth['oauth_token'] session.tumblr_oauth_token_secret = auth['oauth_token_secret'] raise web.SeeOther(auth_url)
import sys from tumblpy import Tumblpy key = raw_input('App Consumer Key: ') secret = raw_input('App Consumer Secret: ') if not 'skip-auth' in sys.argv: t = Tumblpy(key, secret) callback_url = raw_input('Callback URL: ') auth_props = t.get_authentication_tokens(callback_url=callback_url) auth_url = auth_props['auth_url'] OAUTH_TOKEN_SECRET = auth_props['oauth_token_secret'] print('Connect with Tumblr via: {}'.format(auth_url)) oauth_token = raw_input('OAuth Token (from callback url): ') oauth_verifier = raw_input('OAuth Verifier (from callback url): ') t = Tumblpy(key, secret, oauth_token, OAUTH_TOKEN_SECRET) authorized_tokens = t.get_authorized_tokens(oauth_verifier) final_oauth_token = authorized_tokens['oauth_token'] final_oauth_token_secret = authorized_tokens['oauth_token_secret'] print('OAuth Token: {}'.format(final_oauth_token)) print('OAuth Token Secret: {}'.format(final_oauth_token_secret))
# Set up argument parser, read in username parser = argparse.ArgumentParser() parser.add_argument('-b', dest='blog', action='store', required=True, help='blog to check') parser.add_argument('-c', dest='consumer', action='store', required=True, help='consumer key') parser.add_argument('-s', dest='secret', action='store', required=True, help='secret key') flags = parser.parse_args() blog = flags.blog blog_url = "http://" + blog + ".tumblr.com/" consumer = flags.consumer secret = flags.secret # Authenticate on Tumblr t = Tumblpy(consumer, secret) auth_props = t.get_authentication_tokens() auth_url = auth_props['auth_url'] OAUTH_TOKEN_SECRET = auth_props['oauth_token_secret'] print "You're into Tumblr!" # Get the number of posts to evaluate posts = t.get('info', blog_url=blog_url) num_posts = posts['blog']['posts'] print "There are " + str(num_posts) + " posts to examine..." # Iterate through posts, searching for self-text posts, saving body of each post f = open((blog + '.txt'),'w') count = 0 texts = []