evernote-hello-world
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEvernote Hello World
Evernote Hello World
Overview
概述
Create your first Evernote note using the Cloud API, demonstrating ENML format and NoteStore operations.
使用Cloud API创建你的第一个Evernote笔记,演示ENML格式和NoteStore操作。
Prerequisites
前提条件
- Completed setup
evernote-install-auth - Valid access token (OAuth or Developer Token for sandbox)
- Development environment ready
- 完成配置
evernote-install-auth - 有效的访问令牌(沙箱环境使用OAuth或开发者令牌)
- 开发环境已准备就绪
Instructions
操作步骤
Step 1: Create Entry File
步骤1:创建入口文件
javascript
// hello-evernote.js
const Evernote = require('evernote');
// Initialize authenticated client
const client = new Evernote.Client({
token: process.env.EVERNOTE_ACCESS_TOKEN,
sandbox: true // Set to false for production
});javascript
// hello-evernote.js
const Evernote = require('evernote');
// Initialize authenticated client
const client = new Evernote.Client({
token: process.env.EVERNOTE_ACCESS_TOKEN,
sandbox: true // Set to false for production
});Step 2: Understand ENML Format
步骤2:了解ENML格式
Evernote uses ENML (Evernote Markup Language), a restricted subset of XHTML:
xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>
<h1>Note Title</h1>
<p>This is a paragraph.</p>
<div>Content goes here</div>
</en-note>Key ENML Rules:
- Must include XML declaration and DOCTYPE
- Root element is , not
<en-note>or<html><body> - All tags must be lowercase and properly closed
- No ,
<script>,<form>, or event handlers<iframe> - Inline styles only (no or
classattributes)id
Evernote使用ENML(Evernote标记语言),是XHTML的受限子集:
xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>
<h1>Note Title</h1>
<p>This is a paragraph.</p>
<div>Content goes here</div>
</en-note>ENML核心规则:
- 必须包含XML声明和DOCTYPE
- 根元素为,而非
<en-note>或<html><body> - 所有标签必须小写且正确闭合
- 不允许使用、
<script>、<form>或事件处理程序<iframe> - 仅支持内联样式(不允许或
class属性)id
Step 3: Create Your First Note
步骤3:创建你的第一个笔记
javascript
async function createHelloWorldNote() {
const noteStore = client.getNoteStore();
// Define ENML content (required format)
const content = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>
<h1>Hello from Claude Code!</h1>
<p>This is my first note created via the Evernote API.</p>
<p>Created at: ${new Date().toISOString()}</p>
<hr/>
<div style="color: #666;">
<en-todo checked="false"/> Learn Evernote API basics<br/>
<en-todo checked="true"/> Install SDK<br/>
<en-todo checked="true"/> Configure authentication<br/>
</div>
</en-note>`;
// Create note object
const note = new Evernote.Types.Note();
note.title = 'Hello World - Evernote API';
note.content = content;
// Optional: specify notebook (uses default if not set)
// note.notebookGuid = 'your-notebook-guid';
try {
const createdNote = await noteStore.createNote(note);
console.log('Note created successfully!');
console.log('Note GUID:', createdNote.guid);
console.log('Note Title:', createdNote.title);
console.log('Created:', new Date(createdNote.created));
return createdNote;
} catch (error) {
console.error('Failed to create note:', error);
throw error;
}
}
createHelloWorldNote();javascript
async function createHelloWorldNote() {
const noteStore = client.getNoteStore();
// Define ENML content (required format)
const content = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>
<h1>Hello from Claude Code!</h1>
<p>This is my first note created via the Evernote API.</p>
<p>Created at: ${new Date().toISOString()}</p>
<hr/>
<div style="color: #666;">
<en-todo checked="false"/> Learn Evernote API basics<br/>
<en-todo checked="true"/> Install SDK<br/>
<en-todo checked="true"/> Configure authentication<br/>
</div>
</en-note>`;
// Create note object
const note = new Evernote.Types.Note();
note.title = 'Hello World - Evernote API';
note.content = content;
// Optional: specify notebook (uses default if not set)
// note.notebookGuid = 'your-notebook-guid';
try {
const createdNote = await noteStore.createNote(note);
console.log('Note created successfully!');
console.log('Note GUID:', createdNote.guid);
console.log('Note Title:', createdNote.title);
console.log('Created:', new Date(createdNote.created));
return createdNote;
} catch (error) {
console.error('Failed to create note:', error);
throw error;
}
}
createHelloWorldNote();Step 4: Python Version
步骤4:Python版本
python
from evernote.api.client import EvernoteClient
from evernote.edam.type.ttypes import Note
import ospython
from evernote.api.client import EvernoteClient
from evernote.edam.type.ttypes import Note
import osInitialize client
Initialize client
client = EvernoteClient(
token=os.environ['EVERNOTE_ACCESS_TOKEN'],
sandbox=True
)
note_store = client.get_note_store()
client = EvernoteClient(
token=os.environ['EVERNOTE_ACCESS_TOKEN'],
sandbox=True
)
note_store = client.get_note_store()
Create note content in ENML format
Create note content in ENML format
content = '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>
<h1>Hello from Python!</h1>
<p>This note was created using the Evernote Python SDK.</p>
</en-note>'''content = '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>
<h1>Hello from Python!</h1>
<p>This note was created using the Evernote Python SDK.</p>
</en-note>'''Create and submit note
Create and submit note
note = Note()
note.title = 'Hello World - Python'
note.content = content
created_note = note_store.createNote(note)
print(f'Note created: {created_note.guid}')
undefinednote = Note()
note.title = 'Hello World - Python'
note.content = content
created_note = note_store.createNote(note)
print(f'Note created: {created_note.guid}')
undefinedStep 5: List Notebooks
步骤5:列出笔记本
javascript
async function listNotebooks() {
const noteStore = client.getNoteStore();
const notebooks = await noteStore.listNotebooks();
console.log('Your notebooks:');
notebooks.forEach(notebook => {
console.log(`- ${notebook.name} (${notebook.guid})`);
if (notebook.defaultNotebook) {
console.log(' ^ Default notebook');
}
});
return notebooks;
}javascript
async function listNotebooks() {
const noteStore = client.getNoteStore();
const notebooks = await noteStore.listNotebooks();
console.log('Your notebooks:');
notebooks.forEach(notebook => {
console.log(`- ${notebook.name} (${notebook.guid})`);
if (notebook.defaultNotebook) {
console.log(' ^ Default notebook');
}
});
return notebooks;
}Step 6: Retrieve a Note
步骤6:获取笔记
javascript
async function getNote(noteGuid) {
const noteStore = client.getNoteStore();
// Options: withContent, withResourcesData, withResourcesRecognition, withResourcesAlternateData
const note = await noteStore.getNote(noteGuid, true, false, false, false);
console.log('Title:', note.title);
console.log('Content:', note.content);
console.log('Tags:', note.tagGuids);
return note;
}javascript
async function getNote(noteGuid) {
const noteStore = client.getNoteStore();
// Options: withContent, withResourcesData, withResourcesRecognition, withResourcesAlternateData
const note = await noteStore.getNote(noteGuid, true, false, false, false);
console.log('Title:', note.title);
console.log('Content:', note.content);
console.log('Tags:', note.tagGuids);
return note;
}Complete Example
完整示例
javascript
// complete-hello.js
const Evernote = require('evernote');
async function main() {
const client = new Evernote.Client({
token: process.env.EVERNOTE_ACCESS_TOKEN,
sandbox: true
});
const noteStore = client.getNoteStore();
const userStore = client.getUserStore();
// 1. Get user info
const user = await userStore.getUser();
console.log(`Hello, ${user.username}!`);
// 2. List notebooks
const notebooks = await noteStore.listNotebooks();
console.log(`You have ${notebooks.length} notebooks`);
// 3. Create a note
const content = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>
<p>Hello, Evernote!</p>
</en-note>`;
const note = new Evernote.Types.Note();
note.title = 'My First API Note';
note.content = content;
const created = await noteStore.createNote(note);
console.log(`Created note: ${created.guid}`);
// 4. Read it back
const fetched = await noteStore.getNote(created.guid, true, false, false, false);
console.log('Note content retrieved successfully');
}
main().catch(console.error);javascript
// complete-hello.js
const Evernote = require('evernote');
async function main() {
const client = new Evernote.Client({
token: process.env.EVERNOTE_ACCESS_TOKEN,
sandbox: true
});
const noteStore = client.getNoteStore();
const userStore = client.getUserStore();
// 1. Get user info
const user = await userStore.getUser();
console.log(`Hello, ${user.username}!`);
// 2. List notebooks
const notebooks = await noteStore.listNotebooks();
console.log(`You have ${notebooks.length} notebooks`);
// 3. Create a note
const content = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>
<p>Hello, Evernote!</p>
</en-note>`;
const note = new Evernote.Types.Note();
note.title = 'My First API Note';
note.content = content;
const created = await noteStore.createNote(note);
console.log(`Created note: ${created.guid}`);
// 4. Read it back
const fetched = await noteStore.getNote(created.guid, true, false, false, false);
console.log('Note content retrieved successfully');
}
main().catch(console.error);Output
输出结果
- Working code file with Evernote client initialization
- Successfully created note in your Evernote account
- Console output showing:
Hello, yourUsername!
You have 3 notebooks
Created note: 12345678-abcd-1234-efgh-123456789012
Note content retrieved successfully- 可运行的Evernote客户端初始化代码文件
- 在你的Evernote账户中成功创建笔记
- 控制台输出示例:
Hello, yourUsername!
You have 3 notebooks
Created note: 12345678-abcd-1234-efgh-123456789012
Note content retrieved successfullyError Handling
错误处理
| Error | Cause | Solution |
|---|---|---|
| Invalid ENML content | Validate against ENML DTD |
| Note or notebook not found | Check GUID is correct |
| Too many requests | Wait for |
| ENML missing required header | Add XML declaration and DOCTYPE |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 无效的ENML内容 | 根据ENML DTD验证内容 |
| 笔记或笔记本不存在 | 检查GUID是否正确 |
| 请求次数过多 | 等待 |
| ENML缺少必需的头部 | 添加XML声明和DOCTYPE |
ENML Quick Reference
ENML快速参考
html
<!-- Allowed -->
<p>, <div>, <span>, <br/>, <hr/>
<h1>-<h6>, <b>, <i>, <u>, <strong>, <em>
<ul>, <ol>, <li>, <table>, <tr>, <td>
<a href="...">, <img src="...">
<en-todo checked="false"/>
<en-media type="image/png" hash="..."/>
<!-- NOT Allowed -->
<script>, <form>, <input>, <button>
<iframe>, <object>, <embed>
class="...", id="...", onclick="..."html
<!-- Allowed -->
<p>, <div>, <span>, <br/>, <hr/>
<h1>-<h6>, <b>, <i>, <u>, <strong>, <em>
<ul>, <ol>, <li>, <table>, <tr>, <td>
<a href="...">, <img src="...">
<en-todo checked="false"/>
<en-media type="image/png" hash="..."/>
<!-- NOT Allowed -->
<script>, <form>, <input>, <button>
<iframe>, <object>, <embed>
class="...", id="...", onclick="..."Resources
参考资源
Next Steps
下一步
Proceed to for development workflow setup.
evernote-local-dev-loop继续学习以配置开发工作流。
evernote-local-dev-loop