Setting NoteFilter in Evernote API

2019-05-26 23:16发布

问题:

I have set up my Python page like so (extract):

import evernote.edam.userstore.constants as UserStoreConstants
import evernote.edam.type.ttypes as Types
from evernote.api.client import EvernoteClient

client = EvernoteClient(token=auth_token, sandbox=False)
note_store = client.get_note_store()

The problem comes with this code:

filter = note_store.NoteFilter
filter.setOrder(NoteSortOrder.UPDATED.getValue())

I would then go onto use note_store.findNotesMetadata. However, I get the error:

AttributeError: 'module' object has no attribute 'setOrder'

What am I doing wrong? I tried to adapt from the example given here

回答1:

Here is a working example:

from evernote.api.client import EvernoteClient
from evernote.edam.notestore.ttypes import NoteFilter, NotesMetadataResultSpec
from evernote.edam.type.ttypes import NoteSortOrder

auth_token = 'your-token'
client = EvernoteClient(token=auth_token)
note_store = client.get_note_store()

updated_filter = NoteFilter(order=NoteSortOrder.UPDATED)
offset = 0
max_notes = 10
result_spec = NotesMetadataResultSpec(includeTitle=True)
result_list = note_store.findNotesMetadata(auth_token, updated_filter, offset, max_notes, result_spec)

# note is an instance of NoteMetadata
# result_list is an instance of NotesMetadataList
for note in result_list.notes:
    print note.title