Как составить список всех заметок из блокнота Evernote — Javascript/Node.Js

Я настроил свое приложение node.js/express для работы с API Evernote, используя их SDK.

Теперь мне нужно получить список всех заметок из блокнота.

Я успешно получаю список ноутбуков, используя этот код:

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

Кто-нибудь знает, как я могу изменить его, чтобы получить список всех заметок из определенного ноутбука, для которого я знаю GUID?

Спасибо!


person Aerodynamika    schedule 04.07.2014    source источник
comment
ты пробовал noteStore.getNotebook(req.session.oauthAccessToken, [GUID]);?   -  person shennan    schedule 05.07.2014
comment
Кажется, очень сложно найти официальные простые примеры, которые делают базовые вещи с API Evernote. Образцы, которые я видел, неполны, и не делают таких вещей.   -  person Cheeso    schedule 17.11.2016


Ответы (2)


Вот код, который должен работать. Просто измените note.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 метод.

Вот полностью рабочий (после добавления вашего токен разработчика) пример кода, который извлекает все заметки из записной книжки по умолчанию и записывает названия заметок:

  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'? 
person matthewayne    schedule 28.01.2015

Вам нужно использовать метод findNotesMetadata с фильтром. Взгляните на документ: http://dev.evernote.com/doc/reference/NoteStore.html#Fn_NoteStore_findNotesMetadata

Код должен быть примерно таким (не тестировался. Но это даст вам идею.):

var mynotebook = notebooks[0];
var filter = new NoteFilter();
var resultSpec = new resultSpec();

# this determines which info you'll get for each note
resultSpec.includeTitle  = true
resultSpec.includeContentLength = true
resultSpec.includeCreated = true
resultSpec.includeUpdated = true
resultSpec.includeDeleted = true
resultSpec.includeUpdateSequenceNum = true
resultSpec.includeNotebookGuid = true
resultSpec.includeTagGuids = true
resultSpec.includeAttributes = true
resultSpec.includeLargestResourceMime = true
resultSpec.includeLargestResourceSize = true

filter.notebookGuid = mynotebook.guid;
notes = noteStore.findNotesMetadata(authToken, filter, 0, 10, resultSpec);
person Laurent Sarrazin    schedule 07.07.2014