Created
March 8, 2009 04:58
-
-
Save jacobian/75572 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib2 | |
from oauth import oauth | |
CONSUMER_KEY = 'szvErAxSLbVn25RD' | |
CONSUMER_SECRET = 'WxbMH22kUkjRgUz4' | |
CALLBACK_URL = 'http://jacobian.org/' | |
class TimetricOAuthClient(oauth.OAuthClient): | |
request_token_url = 'http://timetric.com/oauth/request_token/' | |
authorization_url = 'http://timetric.com/oauth/authorize/' | |
access_token_url = 'http://timetric.com/oauth/access_token/' | |
def __init__(self): | |
self.http = httplib2.Http() | |
def _fetch_token(self, uri, req): | |
print "Fetch token:", uri | |
print " Headers:", req.to_header() | |
print " Request:", req | |
resp, body = self.http.request(uri, req.http_method, headers=req.to_header()) | |
def fetch_request_token(self, req): | |
resp, body = self.http.request(req.to_url(), 'GET') | |
return oauth.OAuthToken.from_string(body) | |
def fetch_access_token(self, req): | |
raise Exception() | |
def authorize_token(self, req): | |
resp, body = self.http.request(req.to_url(), req.http_method) | |
return body | |
if __name__ == '__main__': | |
httplib2.debuglevel = 2 | |
client = TimetricOAuthClient() | |
consumer = oauth.OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET) | |
signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1() | |
print "*** Fetch request token" | |
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, http_url=client.request_token_url) | |
oauth_request.sign_request(signature_method, consumer, None) | |
token = client.fetch_request_token(oauth_request) | |
print token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment