java.lang.Object | |
↳ | com.evernote.client.android.EvernoteSession |
Represents a session with the Evernote web service API. Used to authenticate to the service via OAuth and obtain NoteStore.Client objects, which are used to make authenticated API calls. To use EvernoteSession, first initialize the EvernoteSession singleton and initiate authentication at an appropriate time:
EvernoteSession session = EvernoteSession.init(...); if (!session.isLoggedIn()) { session.authenticate(...); }When authentication completes, you will want to trap the result in onActivityResult to see if it was successful:
public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch(requestCode) { case EvernoteSession.REQUEST_CODE_OAUTH: if (resultCode == Activity.RESULT_OK) { // OAuth login was successful, do the appropriate thing for your app } break; } }Later, you can make any Evernote API calls that you need by obtaining a NoteStore.Client from the session and using the session's auth token:
NoteStore.client noteStore = session.createNoteStoreClient(); Notebook notebook = noteStore.getDefaultNotebook(session.getAuthToken());class created by @tylersmithnet
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
enum | EvernoteSession.EvernoteService | Evernote Service to use with the bootstrap profile detection. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | HOST_CHINA | ||||||||||
String | HOST_PRODUCTION | ||||||||||
String | HOST_SANDBOX | ||||||||||
int | REQUEST_CODE_OAUTH |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
authenticate(Context ctx)
Start the OAuth authentication process.
| ||||||||||
String |
getAuthToken()
Get the authentication token that is used to make API calls
though a NoteStore.Client.
| ||||||||||
AuthenticationResult |
getAuthenticationResult()
Get the authentication information returned by a successful
OAuth authentication to the Evernote web service.
| ||||||||||
ClientFactory |
getClientFactory()
Use this to create
AsyncNoteStoreClient and AsyncUserStoreClient
| ||||||||||
static EvernoteSession |
getInstance(Context ctx, String consumerKey, String consumerSecret, EvernoteSession.EvernoteService evernoteService)
Use to acquire a singleton instance of the EvernoteSession for authentication.
| ||||||||||
boolean |
isLoggedIn()
Check whether the session has valid authentication information
that will allow successful API calls to be made.
| ||||||||||
void |
logOut(Context ctx)
Clear all stored authentication information.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
BootstrapManager | getBootstrapSession() | ||||||||||
boolean |
persistAuthenticationToken(Context ctx, EvernoteAuthToken authToken, String evernoteHost)
Called upon completion of the OAuth process to save resulting authentication
information into the application's SharedPreferences, allowing it to be reused
later.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Start the OAuth authentication process. TODO do we need to do anything special here if you're already logged in?
Get the authentication token that is used to make API calls though a NoteStore.Client.
isLoggedIn()
is false.
Get the authentication information returned by a successful OAuth authentication to the Evernote web service.
Use this to create AsyncNoteStoreClient
and AsyncUserStoreClient
Use to acquire a singleton instance of the EvernoteSession for authentication. If the singleton has already been initialized, the existing instance will be returned (and the parameters passed to this method will be ignored).
consumerKey | The consumer key portion of your application's API key. |
---|---|
consumerSecret | The consumer secret portion of your application's API key. |
evernoteService | The enum of the Evernote service instance that you wish
to use. Development and testing is typically performed against SANDBOX .
The production Evernote service is HOST_PRODUCTION . |
IllegalArgumentException |
---|
Check whether the session has valid authentication information that will allow successful API calls to be made.
Clear all stored authentication information.
Called upon completion of the OAuth process to save resulting authentication information into the application's SharedPreferences, allowing it to be reused later.
ctx | Application Context or activity |
---|---|
authToken | The authentication information returned at the end of a successful OAuth authentication. |
evernoteHost | the URL of the Evernote Web API to connect to, provided by the bootstrap results |