POST
Watching for changes (Polling notifications) in Evernote
via https://dev.evernote.com/doc/articles/polling_notification.php
Polling
If your app wants to know about changes in a user's Evernote account, you'll probably consider calling the NoteStore.findNotesMetadata function periodically to search for new notes. findNotes is incredibly powerful, but it's also expensive for our servers - we need to load the user's Lucene index, perform the search across all of their notes, hit the database to pull out the results, and send those results over the network to your app. If you're building a web application, you should use webhooks instead of polling. If you have to poll, you should follow the guidelines below.
First, don't poll more than once every 15 minutes. We keep track of calls to findNotes, and if we notice that your app is polling more frequently, we'll have to temporarily revoke your API key.
Each Evernote account has a variable named updateCount that makes it easy for you to tell whether the account has been changed since the last time you looked. Before your application searches for new notes, call NoteStore.getSyncState to check the updateCount and see if the account has changed. Here's a basic example of how that would work:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
int latestUpdateCount = ... // Persist this value
// Each time you want to check for new and updated notes...
SyncState currentState = noteStore.getSyncState();
int currentUpdateCount = currentState.getUpdateCount();
if (currentUpdateCount > latestUpdateCount) {
// Something in the account has changed, so search for notes
NotesMetadataList newNotes = noteStore.findNotesMetadata( ... );
// Do something with the notes you found...
for (NoteMetadata note : newNotes.getNotes()) {
// ...
}
// Keep track of the new high-water mark
latestUpdateCount = currentSyncState.getUpdateCount();
}
|