我正在开发一个web应用程序,我需要创建一个evernote笔记本,并在其中传输一些文件。
我可以验证来自Evernote的用户,但无法创建笔记本。我也不知道如何在笔记本上传输文件。
这是认证码。API URL
创建笔记本:
noteStore.createNotebook(access_token.token, "my_notebook")
错误:
An error occurred: undefined method `write' for "my_notebook":String
编辑
在赛斯的带领下
notebook = Evernote::EDAM::Type::Notebook.new()
notebook.name = "my_notebook3"
x= noteStore.createNotebook(access_token.token, notebook)
note = Evernote::EDAM::Type::Note.new()
note.notebookGuid = x.guid
note.title="my note"
y=noteStore.createNote(access_token.token,note)
在那个笔记里处理文件传输。
最佳答案
第二个参数是笔记本结构,而不是字符串。你需要做如下事情:
notebook = Evernote::EDAM::Type::Notebook.new()
notebook.name = "my_notebook"
noteStore.createNotebook(access_token.token, notebook)
Evernote笔记本只包含笔记,笔记可以附加文件。要将文件附加到新便笺,需要创建资源并将其包含在便笺中:
filename = # the file that you want to attach
image = File.open(filename, "rb") { |io| io.read }
hashFunc = Digest::MD5.new
hashHex = hashFunc.hexdigest(image)
data = Evernote::EDAM::Type::Data.new()
data.size = image.size
data.bodyHash = hashHex
data.body = image
resource = Evernote::EDAM::Type::Resource.new()
resource.mime = # the appropriate MIME type
resource.data = data
resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new()
resource.attributes.fileName = filename
note = Evernote::EDAM::Type::Note.new()
note.title = "Title"
note.content = '<?xml version="1.0" encoding="UTF-8"?>' +
'<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' +
'<en-note>' +
'<en-media type="' + resource.mime + '" hash="' + hashHex + '"/>' +
'</en-note>'
note.resources = [ resource ]
createdNote = noteStore.createNote(authToken, note)
evernote api zip文件中的示例代码演示了这一点。您可以从http://www.evernote.com/about/developer/api/下载zip。