OAuth process with Evernote fails with "Oops, we encountered an error"

168 Views Asked by At

After investing some days in experiments I need to ask for assistance here.

I used a devToken to write and try my code and want to change to production now. As I see, production requires to use OAuth instead and doesn't allow a devToken, even not for personal use. So I try to implement an OAuth, but fail at get_access_token() as Evernotes side returns the error "Oops, we encountered an error" instead the oauth_token.

The difficulty for me is to decide whether it is on me or on Evernote. Can anyone give me a hint?

My code is the following: (based on https://gist.github.com/brettkelly/5041037)

# Python OAuth example
from evernote.api.client import EvernoteClient


##
# Helper function to turn query string parameters into a
# Python dictionary
##
def parse_query_string(authorize_url):
    uargs = 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


##
# Create an instance of EvernoteClient using your API
# key (consumer key and consumer secret)
##
client = EvernoteClient(
    consumer_key='xxxx',
    consumer_secret='yyyy',
    sandbox=True)

request_token = client.get_request_token('http://localhost')

print("Paste this URL in your browser and login")
print('\t'+client.get_authorize_url(request_token))
print('-------')

after_accept_url = 'http://localhost/?oauth_token=1111&oauth_verifier=2222&sandbox_lnb=false'
vals = parse_query_string(after_accept_url)

print(f"Auth Token: {request_token['oauth_token']}")
print(f"Auth Secret: {request_token['oauth_token_secret']}")
print(f"OAuth verifier: {vals['oauth_verifier']}")

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

# Create a new client using the auth token
client = EvernoteClient(token=auth_token)
userStore = client.get_user_store()
user = userStore.getUser()
print(user.username)
2

There are 2 best solutions below

0
mstuebner On

Today I ran the identical code again and got the expected access_token (auth_token in the code) instead of the error "Ooops". So it was an error on evernotes side. The returned access_token proved to work, so I leave this as an example of a working OAuth with Evernote on Python 3.x.

0
JimP On

I encountered the same problem - in case it helps anybody, it turned out I was using the Eventote sandbox but trying to authenticate on Evernote Production.