javascript - Evernote API NoteStore#updateNote 修改笔记更新时间,无论实际更改哪个字段

标签 javascript python node.js evernote

作者:this , 如果我只修改笔记的标签列表,则不应算作更新。因此 note.updated 保留旧值。

当我使用官方客户端手动添加或删除笔记中的标签时,情况就是如此。

尝试去做

以编程方式向现有笔记(标题为“test01”)添加新标签,同时不更新 note.updated。 有点像模拟官方客户端修改标签列表的行为。

使用的Python代码

插入您自己的开发 token 后,它应该可以直接执行。

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()

结果

  1. [如预期]新标签已成功添加。
  2. [不符合预期] note.updated 已修改。不仅本地数据,远程数据也反射(reflect)了这种修改。我已经用官方网络应用程序检查过了。

额外01

即使我将 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 字段。此行为与官方客户端不一样。

额外02

我什至尝试使用 Javascript API 实现相同的逻辑。结果保持不变。

问题

我做错了什么吗? 或者使用 Evernote API 根本不可能做到这一点?

最佳答案

尝试

spec = NoteStore.NotesMetadataResultSpec()
spec.includeTitle = True
spec.includeTagGuids = True
spec.includeUpdated = True

这将在 NoteStore.findNotesMetadata 返回的注释中预填充 Note.updated。然后,使用带有 updated 的注释来调用 NoteStore.updateNote,您将看到 updated 字段保留原始值。

关于javascript - Evernote API NoteStore#updateNote 修改笔记更新时间,无论实际更改哪个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46376512/

相关文章:

python - 将代码从 Py3.0 转换为 2.7Py Super() 并打印语句

node.js - mongo更新查询忽略更新操作中的几个字段

javascript - 如何在多个 fabric js Canvas 的情况下管理内存?

javascript - 如何使用 JSP 创建标签式 Html 页面

javascript - 如何访问 JSON Object.$$state.value?

python - 打印出列表每行更改列的索引

javascript - 自动表单手动提交

python - 防止管理命令一次运行多个命令

node.js - 有没有一种方法可以打包Electron应用程序,以使其具有.exe文件和仅包含HTML/JS/CSS文件的文件夹?

node.js - Node js 返回 mongodb 查找结果