evernote-install-auth

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Evernote 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密钥

  1. Go to Evernote Developer Portal
  2. Request an API key via the contact form
  3. Wait for manual approval (up to 5 business days)
  4. Receive your
    consumerKey
    and
    consumerSecret
  1. 访问 Evernote开发者门户
  2. 通过联系表单申请API密钥
  3. 等待人工审核(最长5个工作日)
  4. 获取您的
    consumerKey
    consumerSecret

Step 2: Install SDK

步骤2:安装SDK

bash
set -euo pipefail
bash
set -euo pipefail

Node.js

Node.js

npm install evernote
npm install evernote

Python

Python

pip install evernote
undefined
pip install evernote
undefined

Step 3: Configure Environment

步骤3:配置环境变量

bash
undefined
bash
undefined

Create .env file

创建.env文件

cat << 'EOF' >> .env EVERNOTE_CONSUMER_KEY=your-consumer-key EVERNOTE_CONSUMER_SECRET=your-consumer-secret EVERNOTE_SANDBOX=true EOF
undefined
cat << 'EOF' >> .env EVERNOTE_CONSUMER_KEY=your-consumer-key EVERNOTE_CONSUMER_SECRET=your-consumer-secret EVERNOTE_SANDBOX=true EOF
undefined

Step 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
undefined
javascript
// 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
undefined

Python - Initialize client

Python - 初始化客户端

from evernote.api.client import EvernoteClient
client = EvernoteClient( consumer_key='your-consumer-key', consumer_secret='your-consumer-secret', sandbox=True )
undefined
from evernote.api.client import EvernoteClient
client = EvernoteClient( consumer_key='your-consumer-key', consumer_secret='your-consumer-secret', sandbox=True )
undefined

Step 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:
  1. Create a sandbox account at https://sandbox.evernote.com
  2. Get a Developer Token from https://sandbox.evernote.com/api/DeveloperToken.action
  3. 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流程:
  1. https://sandbox.evernote.com创建沙箱账户
  2. https://sandbox.evernote.com/api/DeveloperToken.action获取开发令牌
  3. 直接使用,无需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

错误处理

ErrorCauseSolution
Invalid consumer key
Wrong or unapproved keyVerify key from developer portal
OAuth signature mismatch
Incorrect consumer secretCheck secret matches portal
Token expired
Access token > 1 year oldRe-authenticate user via OAuth
RATE_LIMIT_REACHED
Too many API callsImplement exponential backoff
Permission denied
Insufficient API key permissionsRequest additional permissions
错误原因解决方案
Invalid consumer key
密钥错误或未通过审核验证开发者门户中的密钥
OAuth signature mismatch
Consumer Secret不正确检查密钥是否与门户一致
Token expired
访问令牌已超过1年有效期通过OAuth重新认证用户
RATE_LIMIT_REACHED
API调用次数过多实现指数退避机制
Permission denied
API密钥权限不足申请额外权限

Token Expiration

令牌过期

  • Default token validity: 1 year
  • Users can reduce to: 1 day, 1 week, or 1 month
  • Expiration timestamp in
    edam_expires
    parameter
  • Implement token refresh before expiration
  • 默认令牌有效期:1年
  • 用户可将有效期缩短为:1天、1周或1个月
  • 过期时间戳包含在
    edam_expires
    参数中
  • 请在令牌过期前实现刷新逻辑

Resources

参考资源

Next Steps

后续步骤

After successful auth, proceed to
evernote-hello-world
for your first note creation.
认证成功后,请继续参考
evernote-hello-world
完成您的第一条笔记创建。

Examples

示例

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安装与认证流程,满足多约束条件与团队特定需求。