Introduction
pycloc is a Python-based OAuth 1.0a client, aimed at being straightforward to use, in the same way as cURL.
Requirements
pycloc requires Python 2.5+ (possibly works on 2.4, but untested), httplib2 and PyYAML.
Twitter Quickstart
-
Register your application with Twitter to get a consumer key and secret.
-
Obtain your request token:
pycloc 'https://api.twitter.com/oauth/request_token' -a 'oauth_callback=oob' --request-token -k $CONSUMER_KEY -K $CONSUMER_SECRET
-
This will then give you a requst token and secret.
-
Visit
https://api.twitter.com/oauth/authorize?oauth_token=$TOKEN
to authorize the application and obtain a verifier PIN. -
Obtain your access token:
pycloc https://api.twitter.com/oauth/access_token --access-token -V $VERIFIER_PIN
-
Make requests against the API:
pycloc 'http://api.twitter.com/1/statuses/home_timeline.xml' pycloc 'http://api.twitter.com/1/statuses/update.xml' -p -a 'status=Testing pycloc now. Does it work?'
Basic Walkthrough
-
Register your application and get a consumer key and secret
-
Do one of the following:
-
Include
-k $CONSUMER_TOKEN -K $CONSUMER_SECRET
in the first call for a host (e.g. the request_token call). pycloc will save them thereafter. -
Place them into your
~/.pyclocrc
using the hostname of the target API.hosts: api.example.com: consumer-secret: $MY_CONSUMER_SECRET consumer-token: $MY_CONSUMER_TOKEN
-
-
Obtain your request token:
pycloc http://api.example.com/oauth/request_token --request-token
-
This will then give you a request token and secret, and an authorize URL (based on the request_token URL -- adapt as necessary).
-
Visit the authorize URL, authorize the application and obtain a verifier.
-
Obtain your access token:
pycloc http://api.example.com/oauth/access_token --access-token -V $VERIFIER
-
Make requests against the API:
pycloc http://api.example.com/v1/get_data pycloc http://api.example.com/v1/post_something -p -a 'foo=bar' -a 'bz=quux'