evernote-install-auth
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEvernote Install & Auth
Evernote 安装与认证
Overview
概述
Set up Evernote SDK and configure OAuth 1.0a authentication for accessing the Evernote Cloud API.
设置Evernote SDK并配置OAuth 1.0a认证,以访问Evernote Cloud API。
Prerequisites
前置条件
- Node.js 18+ or Python 3.10+
- Package manager (npm, pnpm, or pip)
- Evernote developer account
- API key from Evernote Developer Portal (requires approval, allow 5 business days)
- Node.js 18+ 或 Python 3.10+
- 包管理器(npm、pnpm或pip)
- Evernote开发者账户
- 来自Evernote开发者门户的API密钥(需要审核,耗时约5个工作日)
Instructions
操作步骤
Step 1: Request API Key
步骤1:申请API密钥
- Go to Evernote Developer Portal
- Request an API key via the contact form
- Wait for manual approval (up to 5 business days)
- Receive your and
consumerKeyconsumerSecret
- 访问 Evernote开发者门户
- 通过联系表单申请API密钥
- 等待人工审核(最长5个工作日)
- 获取您的和
consumerKeyconsumerSecret
Step 2: Install SDK
步骤2:安装SDK
bash
set -euo pipefailbash
set -euo pipefailNode.js
Node.js
npm install evernote
npm install evernote
Python
Python
pip install evernote
undefinedpip install evernote
undefinedStep 3: Configure Environment
步骤3:配置环境变量
bash
undefinedbash
undefinedCreate .env file
创建.env文件
cat << 'EOF' >> .env
EVERNOTE_CONSUMER_KEY=your-consumer-key
EVERNOTE_CONSUMER_SECRET=your-consumer-secret
EVERNOTE_SANDBOX=true
EOF
undefinedcat << 'EOF' >> .env
EVERNOTE_CONSUMER_KEY=your-consumer-key
EVERNOTE_CONSUMER_SECRET=your-consumer-secret
EVERNOTE_SANDBOX=true
EOF
undefinedStep 4: Initialize OAuth Client
步骤4:初始化OAuth客户端
javascript
// Node.js - Initialize client for OAuth flow
const Evernote = require('evernote');
const client = new Evernote.Client({
consumerKey: process.env.EVERNOTE_CONSUMER_KEY,
consumerSecret: process.env.EVERNOTE_CONSUMER_SECRET,
sandbox: process.env.EVERNOTE_SANDBOX === 'true',
china: false
});python
undefinedjavascript
// Node.js - 初始化客户端以进行OAuth流程
const Evernote = require('evernote');
const client = new Evernote.Client({
consumerKey: process.env.EVERNOTE_CONSUMER_KEY,
consumerSecret: process.env.EVERNOTE_CONSUMER_SECRET,
sandbox: process.env.EVERNOTE_SANDBOX === 'true',
china: false
});python
undefinedPython - Initialize client
Python - 初始化客户端
from evernote.api.client import EvernoteClient
client = EvernoteClient(
consumer_key='your-consumer-key',
consumer_secret='your-consumer-secret',
sandbox=True
)
undefinedfrom evernote.api.client import EvernoteClient
client = EvernoteClient(
consumer_key='your-consumer-key',
consumer_secret='your-consumer-secret',
sandbox=True
)
undefinedStep 5: Implement OAuth Flow
步骤5:实现OAuth流程
javascript
// Step 5a: Get request token and redirect URL
const callbackUrl = 'http://localhost:3000/oauth/callback'; # 3000: 3 seconds in ms
client.getRequestToken(callbackUrl, (error, oauthToken, oauthTokenSecret) => {
if (error) {
console.error('Failed to get request token:', error);
return;
}
// Store tokens in session (required for callback)
req.session.oauthToken = oauthToken;
req.session.oauthTokenSecret = oauthTokenSecret;
// Redirect user to Evernote authorization page
const authorizeUrl = client.getAuthorizeUrl(oauthToken);
res.redirect(authorizeUrl);
});javascript
// Step 5b: Handle OAuth callback
app.get('/oauth/callback', (req, res) => {
const oauthVerifier = req.query.oauth_verifier;
client.getAccessToken(
req.session.oauthToken,
req.session.oauthTokenSecret,
oauthVerifier,
(error, oauthAccessToken, oauthAccessTokenSecret, results) => {
if (error) {
console.error('Failed to get access token:', error);
return res.status(500).send('Authentication failed'); # HTTP 500 Internal Server Error
}
// Store access token securely (valid for 1 year by default)
req.session.accessToken = oauthAccessToken;
// Token expiration included in results.edam_expires
console.log('Token expires:', new Date(parseInt(results.edam_expires)));
res.redirect('/dashboard');
}
);
});javascript
// 步骤5a:获取请求令牌与重定向URL
const callbackUrl = 'http://localhost:3000/oauth/callback'; # 3000:毫秒单位的3秒
client.getRequestToken(callbackUrl, (error, oauthToken, oauthTokenSecret) => {
if (error) {
console.error('获取请求令牌失败:', error);
return;
}
// 将令牌存储在会话中(回调时必需)
req.session.oauthToken = oauthToken;
req.session.oauthTokenSecret = oauthTokenSecret;
// 重定向用户至Evernote授权页面
const authorizeUrl = client.getAuthorizeUrl(oauthToken);
res.redirect(authorizeUrl);
});javascript
// 步骤5b:处理OAuth回调
app.get('/oauth/callback', (req, res) => {
const oauthVerifier = req.query.oauth_verifier;
client.getAccessToken(
req.session.oauthToken,
req.session.oauthTokenSecret,
oauthVerifier,
(error, oauthAccessToken, oauthAccessTokenSecret, results) => {
if (error) {
console.error('获取访问令牌失败:', error);
return res.status(500).send('认证失败'); # HTTP 500 内部服务器错误
}
// 安全存储访问令牌(默认有效期1年)
req.session.accessToken = oauthAccessToken;
// 令牌过期时间包含在results.edam_expires中
console.log('令牌过期时间:', new Date(parseInt(results.edam_expires)));
res.redirect('/dashboard');
}
);
});Step 6: Verify Connection
步骤6:验证连接
javascript
// Create authenticated client and verify
const authenticatedClient = new Evernote.Client({
token: req.session.accessToken,
sandbox: true
});
const userStore = authenticatedClient.getUserStore();
const noteStore = authenticatedClient.getNoteStore();
// Verify connection
userStore.getUser().then(user => {
console.log('Authenticated as:', user.username);
console.log('User ID:', user.id);
}).catch(err => {
console.error('Authentication verification failed:', err);
});javascript
// 创建已认证客户端并验证
const authenticatedClient = new Evernote.Client({
token: req.session.accessToken,
sandbox: true
});
const userStore = authenticatedClient.getUserStore();
const noteStore = authenticatedClient.getNoteStore();
// 验证连接
userStore.getUser().then(user => {
console.log('已认证用户:', user.username);
console.log('用户ID:', user.id);
}).catch(err => {
console.error('认证验证失败:', err);
});Development Tokens (Sandbox Only)
开发令牌(仅沙箱环境)
For development, you can use a Developer Token instead of full OAuth:
- Create a sandbox account at https://sandbox.evernote.com
- Get a Developer Token from https://sandbox.evernote.com/api/DeveloperToken.action
- Use directly without OAuth flow:
javascript
const client = new Evernote.Client({
token: process.env.EVERNOTE_DEV_TOKEN,
sandbox: true
});
const noteStore = client.getNoteStore();Note: Developer tokens are currently unavailable for production. Use OAuth for production applications.
开发阶段,您可以使用开发令牌替代完整OAuth流程:
- 在https://sandbox.evernote.com创建沙箱账户
- 从https://sandbox.evernote.com/api/DeveloperToken.action获取开发令牌
- 直接使用,无需OAuth流程:
javascript
const client = new Evernote.Client({
token: process.env.EVERNOTE_DEV_TOKEN,
sandbox: true
});
const noteStore = client.getNoteStore();注意: 开发令牌目前无法在生产环境使用。生产应用请使用OAuth。
Output
输出结果
- Installed SDK package in node_modules or site-packages
- Environment variables configured
- Working OAuth flow implementation
- Successful connection verification
- node_modules或site-packages中已安装SDK包
- 已配置环境变量
- 可正常运行的OAuth流程实现
- 连接验证成功
Error Handling
错误处理
| Error | Cause | Solution |
|---|---|---|
| Wrong or unapproved key | Verify key from developer portal |
| Incorrect consumer secret | Check secret matches portal |
| Access token > 1 year old | Re-authenticate user via OAuth |
| Too many API calls | Implement exponential backoff |
| Insufficient API key permissions | Request additional permissions |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 密钥错误或未通过审核 | 验证开发者门户中的密钥 |
| Consumer Secret不正确 | 检查密钥是否与门户一致 |
| 访问令牌已超过1年有效期 | 通过OAuth重新认证用户 |
| API调用次数过多 | 实现指数退避机制 |
| API密钥权限不足 | 申请额外权限 |
Token Expiration
令牌过期
- Default token validity: 1 year
- Users can reduce to: 1 day, 1 week, or 1 month
- Expiration timestamp in parameter
edam_expires - Implement token refresh before expiration
- 默认令牌有效期:1年
- 用户可将有效期缩短为:1天、1周或1个月
- 过期时间戳包含在参数中
edam_expires - 请在令牌过期前实现刷新逻辑
Resources
参考资源
Next Steps
后续步骤
After successful auth, proceed to for your first note creation.
evernote-hello-world认证成功后,请继续参考完成您的第一条笔记创建。
evernote-hello-worldExamples
示例
Basic usage: Apply evernote install auth to a standard project setup with default configuration options.
Advanced scenario: Customize evernote install auth for production environments with multiple constraints and team-specific requirements.
基础用法:将Evernote安装与认证应用于标准项目搭建,使用默认配置选项。
高级场景:针对生产环境自定义Evernote安装与认证流程,满足多约束条件与团队特定需求。