Python & tumblr API: cannot log in to my own tumblr to create posts -


so have consumer key , consumer secret tumblr, , have following code allowing me oauth authentication, have no idea how log in own tumblr through python and/or pytumblr. can't post tumblr after using oauth. supposed login tumblr through api, or log in regularly though http python , use api? old tumblr api hasn't worked since sept 2012 believe, python-tumblr @ here doesn't work more can tell. instead i'm using pytumblr here.

here's code:

import urlparse import oauth2 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 = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx' consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'     def test():     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))     oauthtoken = request_token['oauth_token']     oauthsecret = request_token['oauth_token_secret']        print "request token:\n"     print " - oauth_token        = " + oauthtoken + "\n"     print " - oauth_token_secret = " + oauthsecret + "\n"      pytumblrclient = pytumblr.tumblrrestclient(consumer_key, consumer_secret, oauthtoken, oauthsecret)      response = pytumblrclient.create_text("mytumblr.tumblr.com", body="test")     print response 

as can see there no password tumblr being sent anywhere, , none of documentation tells me send password. not-authorized response after running code:

{u'meta': {u'status': 401, u'msg': u'not authorized'}, u'response': []} 

is there way post own tumblr using tumblr api?

tl;dr workaround instructs user retrieve oauth tokens generated interactive_console.py , hardcode token values instead of retrieving them programmatically.

note: i'm convinced workaround somehow violates entire principle behind oauth's can't figure out why original method doesn't work. appreciate input folks more knowledgable - 1. why workaround not ideal 2. how can fix original method don't have way


workaround:

  1. get 'consumer key' , 'consumer secret' api console page
  2. run interactive_console.py , follow directions
  3. if goes well, both oauth tokens stored in ~/.tumblr (pytumblr readme), , should arrive @ interactive python console

    python 2.7.11 (default, may 19 2016, 13:11:38)  [gcc 4.2.1 compatible apple llvm 7.3.0 (clang-703.0.31)] on darwin type "help", "copyright", "credits" or "license" more information. (interactiveconsole) >>> 
  4. exit out of python console since won't need (type 'exit()' )

  5. retrieve oauth tokens ~/.tumblr

  6. hard code oauth tokens whatever using consistently returning 401 'unauthorized' error. me, looked this: (note << >>)

    import urlparse import oauth2 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 = '<<redacted>>' consumer_secret = '<<redacted>>'  # don't need b/c we're not retrieving oauth tokens programmatically anymore ''' 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)) oauthtoken = request_token['oauth_token'] oauthsecret = request_token['oauth_token_secret']   '''  # original api call oauth tokens retrieved programmatically #pytumblrclient = pytumblr.tumblrrestclient(consumer_key, consumer_secret, oauthtoken, oauthsecret)  # new api call oauth tokens hard-coded pytumblrclient = pytumblr.tumblrrestclient(consumer_key, consumer_secret,  '<<hard_coded_oauth_token>>', '<<hard_coded_oauth_token_secret>>')  response = pytumblrclient.create_text("selfiesindumbo", body="testing via api") print response 

hope helps someone!


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -