wwy

access_tokenを取得しようとするとエラーになります。

Recommended Posts

wwy    0

現在OAuth認証を実装しようと思い、以下のコードを書きました。

def parse_query_string(authorize_url):
    uargs = authorize_url.split('?')
    #vals = authorize_url.split('?')
    vals = {}
    if len(uargs) == 1:
        raise Exception('Invalid Authorization URL')
    for pair in uargs[1].split('&'):
        key, value = pair.split('=', 1)
        vals[key] = value
    return vals

url = ""
if os.environ.has_key('HTTP_HOST') and os.environ.has_key('REQUEST_URI'):
    url = "http://" + os.environ['HTTP_HOST'] + os.environ['REQUEST_URI']

vals = parse_query_string(url)

request_token = client.get_request_token(url)

access_token = client.get_access_token(request_token['oauth_token'],request_token['oauth_token_secret'],vals['oauth_verifier'])

ですが、最後の行でで以下のようなエラーが出ています。

 

KeyError                                  Traceback (most recent call last)
<ipython-input-117-875ccf36fc55> in <module>()
----> 1 access_token = client.get_access_token(request_token['oauth_token'],request_token['oauth_token_secret'],vals['oauth_verifier'])

/Users/yw/.pyenv/versions/anaconda2-4.3.1/lib/python2.7/site-packages/evernote-1.25.0-py2.7.egg/evernote/api/client.pyc in get_access_token(self, oauth_token, oauth_token_secret, oauth_verifier)
     65             oauth_token,
     66             oauth_token_secret,
---> 67             oauth_verifier
     68         )
     69         return access_token_dict['oauth_token']

/Users/yw/.pyenv/versions/anaconda2-4.3.1/lib/python2.7/site-packages/evernote-1.25.0-py2.7.egg/evernote/api/client.pyc in get_access_token_dict(self, oauth_token, oauth_token_secret, oauth_verifier)
     56         resp, content = client.request(self._get_endpoint('oauth'), 'POST')
     57         access_token_dict = dict(urlparse.parse_qsl(content))
---> 58         self.token = access_token_dict['oauth_token']
     59         return access_token_dict
     60 

KeyError: 'oauth_token'

 

調べても解決策がわからなかったのですが、ご存知の方はいらっしゃいますでしょうか?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now