我将自己的node.js / express应用程序设置为使用其SDK来与Evernote api一起使用。

现在,我需要从笔记本中获取所有笔记的列表。

我使用以下代码成功获取了笔记本的列表:

 var client = new Evernote.Client({token: req.session.oauthAccessToken});
    var noteStore = client.getNoteStore();
    notebooks = noteStore.listNotebooks(function(err, notebooks) {
        console.log(notebooks);
 });


有谁知道我该如何修改它才能从我知道GUID的特定笔记本中获取所有笔记的列表?

谢谢!

最佳答案

这是一些应该起作用的代码。只需将notebook.guid更改为所需笔记本的guid:



    //create filter for findNotesMetadata
    filter = new Evernote.NoteFilter();
    //set the notebook guid filter to the GUID of the default notebook
    filter.notebookGuid = notebook.guid; //change this to the GUID of the notebook you want
    //create a new result spec for findNotesMetadata
    resultSpec = new Evernote.NotesMetadataResultSpec();
    //set the result spec to include titles
    resultSpec.includeTitle=true;
    //call findNotesMetadata on the note store
    noteStore.findNotesMetadata(filter, 0, 100, resultSpec, function(err, notesMeta) {
        if (err) {
          console.error('err',err);
        }
        else {
          //log the number of notes found in the default notebook
          console.log("Found "+notesMeta.notes.length+" notes in your default notebook . . .")
          for (var i in notesMeta.notes) {
            //list the title of each note in the default notebook
            console.log(i+": "+notesMeta.notes[i].title);
          }


        }});


请记住,findNotesMetadata返回的是metadataList,而不是实际的注释列表。如果需要内容,则需要通过getNote下载每个注释,但是在为每个注释调用getNote之前,请检查resultsSpec属性以获取可能需要的其他数据,因为可以通过检索到您可能需要的许多数据。 findNotesMetadata方法。

这是一个可以正常工作(一旦添加developer token)的代码示例,该示例从默认笔记本中检索所有笔记并记录笔记标题:

  Evernote = require('evernote').Evernote;

  var authToken = "your developer token";

  if (authToken == "your developer token") {
    console.log("Please fill in your developer token");
    console.log("To get a developer token, visit https://sandbox.evernote.com/api/DeveloperToken.action");
    process.exit(1);
  }

  var client = new Evernote.Client({token: authToken, sandbox: true});

  var userStore = client.getUserStore();
  var noteStore = client.getNoteStore();

  var notebook=noteStore.getDefaultNotebook(function (err, notebook){
    //create filter for findNotesMetadata
    filter = new Evernote.NoteFilter();
    //set the notebook guid filter to the GUID of the default notebook
    filter.notebookGuid = notebook.guid;
    //create a new result spec for findNotesMetadata
    resultSpec = new Evernote.NotesMetadataResultSpec();
    //set the result spec to include titles
    resultSpec.includeTitle=true;
    //call findNotesMetadata on the note store
    noteStore.findNotesMetadata(filter, 0, 100, resultSpec, function(err, notesMeta) {
        if (err) {
          console.error('err',err);
        }
        else {
          //log the number of notes found in the default notebook
          console.log("Found "+notesMeta.notes.length+" notes in your default notebook . . .")
          for (var i in notesMeta.notes) {
            //list the title of each note in the default notebook
            console.log(i+": "+notesMeta.notes[i].title);
          }


        }});

  });


样本输出:

  Found 3 notes in your default notebook . . .
  0: This is a test note!
  1: Hello Developer Forums!!!
  2: How are you doin'?

10-05 20:41