python - How do I make a standalone tool using the tripit API? -
i'm trying make simple commandline application queries tripit pull down data travel history. seem getting stuck somewhere along oauth setup, it's not entirely clear me i'm doing wrong.
i have registered application , been assigned api key , secret. i've stored these in creds.py oauth_key , oauth_secret respectively. i've done initial exchange returned me token , secret i've stored oauth_token , oauth_token_secret respectively. attempt run following program:
#!/usr/bin/env python import sys import time import oauth2 oauth import creds if __name__ == '__main__': url = 'https://api.tripit.com/v1/list/trip/format/json' params = { 'oauth_version': "1.0", 'oauth_nonce': oauth.generate_nonce(), 'oauth_timestamp': int(time.time()) } token = oauth.token(key=creds.oauth_token, secret=creds.oauth_token_secret) consumer = oauth.consumer(key=creds.oauth_key, secret=creds.oauth_secret) params['oauth_token'] = token.key params['oauth_consumer_key'] = consumer.key req = oauth.request(method="get", url=url, parameters=params) print req.to_url() signature_method = oauth.signaturemethod_hmac_sha1() req.sign_request(signature_method, consumer, token) client = oauth.client(consumer) resp, content = client.request(req.to_url(), "get") print resp print content it reports error:
{'status': '401', 'transfer-encoding': 'chunked', 'server': 'nginx', 'connection': 'keep-alive', 'date': 'mon, 04 jul 2011 00:13:15 gmt', 'content-type': 'application/json'} {"error":{"code":401,"detailed_error_code":106.1, "description":"invalid token key: fc0e332517d03a515bf6fca5e3144e022c5f0076"}} (where fc0e332517d03a515bf6fca5e3144e022c5f0076 oauth_token auth step)
has used service might know i'm doing wrong? perhaps i'm doing wrong oauth.
try "?format=json" instead of "/format/json". i've seen work way before (but haven't used json interface).
Comments
Post a Comment