我正在开发一个Web应用程序,我需要创建一个EverNote笔记本并在其中传输一些文件。
我能够从EverNote验证用户,但无法创建笔记本。我也很困惑如何在那个笔记本中传输文件。
这是验证码。 API URL
创建笔记本:
noteStore.createNotebook(access_token.token, "my_notebook")
错误:
An error occurred: undefined method `write' for "my_notebook":String
修改
跟随seth的领先优势
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)
在该笔记中处理文件传输。
答案 0 :(得分:3)
第二个参数是Notebook结构,而不是字符串。您需要执行以下操作:
notebook = Evernote::EDAM::Type::Notebook.new()
notebook.name = "my_notebook"
noteStore.createNotebook(access_token.token, notebook)
Evernote笔记本仅包含Notes,而Notes可以附加文件。要将文件附加到新笔记,您需要创建资源并将其包含在笔记中:
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。