按this,
如果我只修改注释的标签列表,则不应将其视为更新。因此note.updated
仍然是旧值。
当我在官方客户端的笔记中手动添加或删除标签时,这是真的。
以编程方式将新标记添加到现有注释(标题为" test01"),而不更新note.updated
。
有点像在修改标签列表时模拟官方客户端的行为。
插入自己的开发令牌后,应该可以直接执行。
import uuid
from datetime import datetime
from evernote.api.client import EvernoteClient
from evernote.edam.notestore import NoteStore
from evernote.edam.type.ttypes import Tag, Note
def main():
# create note_store
auth_token = "<MyDevToken>"
note_store = EvernoteClient(token=auth_token, sandbox=True).get_note_store()
# create a new tag
the_tag = create_new_tag(auth_token, note_store, "complex_")
print("Tag (%s, %s) created." % (the_tag.guid, the_tag.name))
# search for the note
note_list = remote_search(auth_token, note_store, "intitle:test01")
# add tag to notes found
for note in note_list.notes:
print("Before: %s, tagGuids=%s" % (note.guid, note.tagGuids))
result_note = tag_note(auth_token, note_store, note, the_tag.guid)
print("After: %s, tagGuids=%s, updated=%s" %\
(result_note.guid, result_note.tagGuids,\
datetime.fromtimestamp(result_note.updated/1000)))
pass
def create_new_tag(auth_token, note_store, tag_name_prefix="complex_") -> Tag:
random_tag_name = tag_name_prefix + str(uuid.uuid4())
my_new_tag = Tag(name=random_tag_name)
return note_store.createTag(auth_token, my_new_tag)
def remote_search(auth_token, note_store, search_string):
my_filter = NoteStore.NoteFilter()
my_filter.words = search_string
my_filter.ascending = False
spec = NoteStore.NotesMetadataResultSpec()
spec.includeTitle = True
spec.includeTagGuids = True
return note_store.findNotesMetadata(auth_token, my_filter, 0, 10, spec)
def tag_note(auth_token, note_store, note, tag_guid) -> Note:
if note.tagGuids is None:
note.tagGuids = [tag_guid]
else:
note.tagGuids.append(tag_guid)
return note_store.updateNote(auth_token, note)
if __name__ == '__main__':
main()
note.updated
已修改。不仅本地数据而且远程数据也反映了这种修改。我已经通过官方网络应用程序检查了它。即使我将tag_note()
更改为:
def tag_note(auth_token, note_store, note, tag_guid) -> Note:
# intentionally doing nothing except updateNote()
return note_store.updateNote(auth_token, note)
结果保持不变。似乎无论哪个字段发生变化,updateNote()
api调用都会修改note.updated
字段。此行为与官方客户端不同。
我甚至尝试使用Javascript API实现相同的逻辑。结果保持不变。
我做错了吗? 或者用Evernote API这样做是不可能的?
答案 0 :(得分:0)
尝试
spec = NoteStore.NotesMetadataResultSpec()
spec.includeTitle = True
spec.includeTagGuids = True
spec.includeUpdated = True
这会在Note.updated
返回的备注中预填NoteStore.findNotesMetadata
。然后,使用updated
的注释来呼叫NoteStore.updateNote
,您会看到updated
字段保留原始值。