开发者

How do I make a standalone tool using the tripit API?

I'm trying to make a simple commandline application that queries tripit to pull down data about my travel history. I seem to be getting stuck somewhere along the oauth setup, but it's not entirely clear to me what I'm doing wrong.

I have registered an application and been assigned an API key and secret. I've stored these in creds.py as OAUTH_KEY and OAUTH_SECRET respectively. I've then done an initial exchange which returned me a token and secret which I've stored as OAUTH_TOKEN and OAUTH_TOKEN_SEC开发者_运维知识库RET respectively. Then I attempt to run the following program:

#!/usr/bin/env python

import sys
import time

import oauth2 as 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 an 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 is my OAUTH_TOKEN from the auth step)

Has anyone successfully used this service who might know what I'm doing wrong? Perhaps I'm just doing something wrong with oauth.


Try it with "?format=json" instead of "/format/json". I've seen it work that way before (but haven't used the JSON interface).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜