A Sample of jsOAuth plugin for Google Chrome Extension - using Evernote SDK for JavaScript with Basic Access Permissions
This sample uses the following libraries:
This sample is based on the Evernote SDK for JavaScript Quick-start Guide. (Note that the sample code listed on the Quick-start Guide is somehow not working, please checkout directly to the PhoneGap example using the Evernote SDK for JavaScript for working sample source code.)
You'll need to create an account on Evernote development server.
And then Get An API Key and fill in the consumerKey
and consumerSecret
in your code.
You can revoke access authorization on Applications management page.
Please checkout the Evernote Developer Documentation for complete Evernote API reference.
Released under the MIT. Please see LICENSE in the project root folder for more information.
This sample uses Yeoman, please checkout yeoman.io for installation and tutorial.
- Generate the scaffolding using generator-chrome-extension.
yo chrome-extension
- Add required libraries.
bower install evernote
bower install git://bytespider.github.com/jsOAuth.git
bower install git://github.com/amobiz/jsOAuthChromeEx.git
- In manifest.json, add the required scripts for event/background page.
"background": {
"scripts": [
"bower_components/evernote/evernote-sdk-js/thrift/lib/thrift.js",
"bower_components/evernote/evernote-sdk-js/thrift/lib/thrift-binary.js",
"bower_components/evernote/evernote-sdk-js/generated/Errors_types.js",
"bower_components/evernote/evernote-sdk-js/generated/Limits_types.js",
"bower_components/evernote/evernote-sdk-js/generated/NoteStore.js",
"bower_components/evernote/evernote-sdk-js/generated/NoteStore_types.js",
"bower_components/evernote/evernote-sdk-js/generated/Types_types.js",
"bower_components/evernote/evernote-sdk-js/generated/UserStore.js",
"bower_components/evernote/evernote-sdk-js/generated/UserStore_types.js",
"bower_components/jsOAuth/dist/jsOAuth-1.3.7.js",
"bower_components/jsOAuthChromeEx/app/scripts/jsOAuthChromeEx.js",
"scripts/chromereload.js",
"scripts/client.js",
"scripts/background.js"
]
},
Don't use the minified version of evernote-sdk-js, because we need the "authenticationToken" veriable be reserved, as in the next step.
- In Gruntfile.js, add keyword "authenticationToken" to except in uglify.
uglify: {
options: {
mangle: {
except: ['authenticationToken']
}
}
},
- In manifest.json, add "web_accessible_resources".
"web_accessible_resources": [
"oauth.html"
],
- In manifest.json, add permission to "https://sandbox.evernote.com/".
"permissions": [
"tabs",
"https://sandbox.evernote.com/"
]
- In background.js, setup the jsOAuth:
OAuth.initBackgroundPage();
- To authorize using OAuth, create an Evernote.Client object, and then call it's authorize method.
var client = new Evernote.Client({
consumerKey: 'your consumerKey',
consumerSecret: 'your consumerSecret',
sandbox: true
});
client.authorize(function() {
noteStore = client.getNoteStore();
// call noteStore's method to access Evernote API.
}, function( error ) {
handleEDAMException( error );
});
You'll need to replace the consumer key and secret with your own.
-
Load the sample Chrome Extension in developer mode.
Please checkout Load the extension for instruction.
-
Checkout evernote.js for usage examples.