Within the app
scope, add these lines. Make sure to substitute your consumer key and consumer secret for the placeholder values and remember that you’ll need to change the value of evernoteHostName
to www.evernote.com
when you’re ready to deploy your application in a production environment.
Next, we need to add our login function which begins that OAuth flow.
(Note that you'll want to replace the value of callbackUrl
in your implementation.)
Bind this function to a user action (such as clicking a button or submitting a form) to integrate it with your application. In our PhoneGap example, we’ve bound app.loginWithEvernote
to a button in index.html
:
Notice that we’re passing an object literal to oauth.request
; this object enumerates success
and failure
callback functions. As you’d expect, these will be called when the request succeeds or fails, respectively. Note that a failed login attempt will still result in a successful request; failure
will be called when some mechanical error—such as a network issue—prevents the request from completing.
The following implementation of success
and failure
will complete the OAuth flow and, if the process completes successfully, produce a valid authentication token that can be used to make calls against the Evernote Cloud API. These functions will also need to be defined with the app
scope: