Skip to content

Instantly share code, notes, and snippets.

@evernotegists
Last active February 26, 2024 09:56
Show Gist options
  • Save evernotegists/5137421 to your computer and use it in GitHub Desktop.
Save evernotegists/5137421 to your computer and use it in GitHub Desktop.
success: function(data) {
var isCallBackConfirmed = false;
var token = '';
var vars = data.text.split("&");
for (var i = 0; i < vars.length; i++) {
var y = vars[i].split('=');
if(y[0] === 'oauth_token') {
token = y[1];
}
else if(y[0] === 'oauth_token_secret') {
this.oauth_token_secret = y[1];
localStorage.setItem("oauth_token_secret", y[1]);
}
else if(y[0] === 'oauth_callback_confirmed') {
isCallBackConfirmed = true;
}
}
var ref;
if(isCallBackConfirmed) {
// step 2
ref = window.open(app.evernoteHostName + '/OAuth.action?oauth_token=' + token, '_blank');
ref.addEventListener('loadstart',
function(event) {
var loc = event.url;
if (loc.indexOf(app.evernoteHostName + '/Home.action?gotOAuth.html?') >= 0) {
var index, verifier = '';
var got_oauth = '';
var params = loc.substr(loc.indexOf('?') + 1);
params = params.split('&');
for (var i = 0; i < params.length; i++) {
var y = params[i].split('=');
if(y[0] === 'oauth_verifier') {
verifier = y[1];
}
}
} else if(y[0] === 'gotOAuth.html?oauth_token') {
got_oauth = y[1];
}
// step 3
oauth.setVerifier(verifier);
oauth.setAccessToken([got_oauth, localStorage.getItem("oauth_token_secret")]);
var getData = {'oauth_verifier':verifier};
ref.close();
oauth.request({'method': 'GET', 'url': app.evernoteHostName + '/oauth',
'success': app.success, 'failure': app.failure});
}
);
} else {
// Step 4 : Get the final token
var querystring = app.getQueryParams(data.text);
var authTokenEvernote = querystring.oauth_token;
// authTokenEvernote can now be used to send request to the Evernote Cloud API
// Here, we connect to the Evernote Cloud API and get a list of all of the
// notebooks in the authenticated user's account:
var noteStoreURL = querystring.edam_noteStoreUrl;
var noteStoreTransport = new Thrift.BinaryHttpTransport(noteStoreURL);
var noteStoreProtocol = new Thrift.BinaryProtocol(noteStoreTransport);
var noteStore = new NoteStoreClient(noteStoreProtocol);
noteStore.listNotebooks(authTokenEvernote, function (notebooks) {
console.log(notebooks);
}
},
function onerror(error) {
console.log(error);
});
},
failure: function(error) {
console.log('error ' + error.text);
}
@admbtlr
Copy link

admbtlr commented Jun 26, 2013

There's an error on lines 32-38. They should read:

                            if(y[0] === 'oauth_verifier') {
                                verifier = y[1];
                            } else if(y[0] === 'gotOAuth.html?oauth_token') {
                                got_oauth = y[1];
                            }
                    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment