2

I'm trying to get tumblr "liked" posts for a user at the http://api.tumblr.com/v2/user/likes url. I have registered my app with tumblr and authorized the app to access the user's tumblr data, so I have oauth_consumer_key, oauth_consumer_secret, oauth_token, and oauth_token secret. However, I'm not sure what to do with these details when I make the api call. I'm trying to create a command line script that will just output json for further processing, so a solution in bash (cURL), Perl, or python would be ideal.

2 Answers 2

1

Well if you don't mind using Python I can recommend rauth. There isn't a Tumblr example, but there are real world, working examples for both OAuth 1.0/a and OAuth 2.0. The API is intended to be simple and straight forward. I'm not sure what other requirements you might have, but maybe worth giving it a shot?

Here's a working example to go by if you're interested:

from rauth import OAuth1Service

import re
import webbrowser

# Get a real consumer key & secret from http://www.tumblr.com/oauth/apps
tumblr = OAuth1Service(
    consumer_key='gKRR414Bc2teq0ukznfGVUmb41EN3o0Nu6jctJ3dYx16jiiCsb',
    consumer_secret='DcKJMlhbCHM8iBDmHudA9uzyJWIFaSTbDFd7rOoDXjSIKgMYcE',
    name='tumblr',
    request_token_url='http://www.tumblr.com/oauth/request_token',
    access_token_url='http://www.tumblr.com/oauth/access_token',
    authorize_url='http://www.tumblr.com/oauth/authorize',
    base_url='https://api.tumblr.com/v2/')

request_token, request_token_secret = tumblr.get_request_token()

authorize_url = tumblr.get_authorize_url(request_token)

print 'Visit this URL in your browser: ' + authorize_url
webbrowser.open(authorize_url)
authed_url = raw_input('Copy URL from your browser\'s address bar: ')
verifier = re.search('\oauth_verifier=([^#]*)', authed_url).group(1)

session = tumblr.get_auth_session(request_token,
                                  request_token_secret,
                                  method='POST',
                                  data={'oauth_verifier': verifier})

user = session.get('user/info').json()['response']['user']

print 'Currently logged in as: {name}'.format(name=user['name'])

Full disclosure, I maintain rauth.

Sign up to request clarification or add additional context in comments.

Comments

0

I sort of found an answer. I ended up using OAuth::Consumer in perl to connect to the tumblr API. It's the simplest solution I've found so far and it just works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.