无法在 Evernote 中创建笔记本和传输文件

发布于 2024-10-31 20:45:44 字数 867 浏览 5 评论 0原文

我正在开发一个 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)

在该说明中领导的文件传输工作。

I am developing a web application and I need to create an EverNote notebook and transfer some files in it.

I am able to authenticate user from EverNote but not able to create notebook. I'm also confused how to transfer files in that notebook.

Here is the authentication code. API URL

For creating a notebook:

noteStore.createNotebook(access_token.token, "my_notebook")

Error:

An error occurred: undefined method `write' for "my_notebook":String

edit

following seth's lead

      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)

working on file transfer in that note.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天赋异禀 2024-11-07 20:45:44

第二个参数是 Notebook 结构,而不是字符串。您需要执行以下操作:

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

The second parameter is a Notebook structure, not a string. You need to do something like:

notebook = Evernote::EDAM::Type::Notebook.new()
notebook.name = "my_notebook"
noteStore.createNotebook(access_token.token, notebook)

Evernote notebooks contain only Notes, and Notes can have files attached to them. To attach a file to a new note, you need to create a Resource and include it in the note:

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)

The sample code in the Evernote API ZIP file demonstrates this. You can download the ZIP from http://www.evernote.com/about/developer/api/.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文