2014-07-04 158 views
0

我使用他們的sdk設置了我的node.js/express應用程序以使用Evernote api。如何列出Evernote筆記本中的所有筆記 - Javascript/Node.Js

現在我需要從筆記本中獲得所有筆記的列表。

我順利拿到了使用此代碼的筆記本列表:

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

有誰知道我怎麼能修改它從一個特定的筆記型計算機,我知道GUID得到的所有音符的名單?

謝謝!

+0

你有沒有試過'noteStore.getNotebook(req.session.oauthAccessToken,[GUID]);'? – shennan

+0

似乎很難找到官方可用的簡單樣本,用evernote API做基本的事情。我看到的樣本不完整,不要做這樣的事情。 – Cheeso

回答

2

您需要在過濾器中使用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); 
4

下面是一些代碼,應該工作。只要改變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'? 
相關問題