For security reasons, Evernote javascript api does not normally work on any browsers.
This application works as a proxy server and allows you to use evernote-sdk-js on a pure client side application.
REF
Does the API support CORS (Cross origin resource sharing)
-
Get Evernote API Consumer Key and Consumer Secret from here.
-
Copy
config.json.template
toconfig.json
and fill in your values. -
Install dependencies.
$ npm install
-
Start server
$ node server.js
-
Access to
http:https://localhost:9999/oauth?callbackurl=http:https://xxx.html
Changehttp:https://localhost:9999
andcallbackurl
valuehttp:https://xxx.html
according to your environment. -
You will be redirected to Evernote authentication page.
-
When authentication is successful, you will be redirected to
http:https://xxx.html
with the query paramoauthAccessToken
.NOTE The
oauthAccessToken
is encoded, so you have to decode it bydecodeURIComponent
function. -
You can use
oauthAccessToken
forevernote-sdk-js
by usinghttp:https://localhost:9999/noteStore?oauthAccessToken=yyy
asnoteStoreURL
. -
See also Sample client and REDME.md of "Evernote SDK for JavaScript".
You can see all functions ofNoteStore
here.
Below is a simple application to get the oauthAccessToken
and to show notebook list.
Before using it, download evernote-sdk-minified.js
and store it at js/
directory.
evernote-sdk-minified.js
can be downloaded from production directory of evernote-sdk-js.
<!DOCTYPE html>
<html>
<head>
<script src="js/evernote-sdk-minified.js"></script>
<script type="text/javascript">
function getParameter(name) {
var regex = new RegExp(name + "=(.+?)(&|$)");
try {
return decodeURIComponent(regex.exec(location.search)[1]);
} catch (e) {
return undefined;
}
}
// TODO change to valid server
var proxyServerAddr = "http:https://localhost:9999";
var oauthAccessToken = getParameter("oauthAccessToken");
if (!oauthAccessToken) {
var selfAddr = window.location.href.replace(/window.location.search/, "");
// redirect to auth page
window.location.href = proxyServerAddr + "/oauth" + "?callbackurl=" + selfAddr;
} else {
var noteStoreURL = proxyServerAddr + "/noteStore" + "?oauthAccessToken=" + oauthAccessToken;
var noteStoreTransport = new Thrift.BinaryHttpTransport(noteStoreURL);
var noteStoreProtocol = new Thrift.BinaryProtocol(noteStoreTransport);
var noteStore = new NoteStoreClient(noteStoreProtocol);
// Get the notebook list and display on console.
noteStore.listNotebooks(oauthAccessToken,
function(notebooks) {
console.log(notebooks);
},
function (error) {
console.log(error.errorCode + ": " + error.parameter);
});
}
</script>
</head>
</html>
-
Create a new Heroku app
heroku apps:create APP_NAME
-
Provide API_CONSUMER_KEY and API_CONSUMER_SECRET:
heroku config:set API_CONSUMER_KEY=XXXX API_CONSUMER_SECRET=YYYY
-
Push changes to heroku
git push heroku master
OR
heroku restart
I decided to make this app for StackEdit and consulted Gatekeeper.