Folo 客户端 SDK
Folo的官方JavaScript/TypeScript客户端 - 现代RSS阅读器. 这个SDK使得可以很容易地构建与Folo的RSS管理,读取历史,以及AI-power特性交互的应用程序.
为什么用Folo SDK?
- 横线: 工作在浏览器, Node.js, React Introduct 和其他 JavaScript 环境中
- 类型安全: 具有自动补全和防出错功能的完整类型脚本支持
- 生产准备:被Folo的官方应用软件所使用,并全面处理出错
安装
pnpm add @follow-app/client-sdk
快速启动
import { FollowClient } from '@follow-app/client-sdk'
// Connect to Folo
const follow = new FollowClient({
baseURL: 'https://api.follow.is',
credentials: 'include', // For web apps
})
// Subscribe to an RSS feed
await follow.subscriptions.create({
url: 'https://example.com/rss',
category: 'Technology',
})
// Get your latest unread articles
const articles = await follow.entries.list({
read: false,
limit: 20,
})
// Mark articles as read
await follow.entries.batch.read({
entryIds: articles.data.map((entry) => entry.id),
})
核心特征
* 饲料管理
易地订阅和管理 RSS 种子 :
// Subscribe to feeds
await follow.subscriptions.create({
url: 'https://blog.example.com/rss',
category: 'Tech Blogs',
})
// Get all your subscriptions
const subscriptions = await follow.subscriptions.get()
// Import OPML files
await follow.subscriptions.import({ opmlContent })
* 阅读经验
跟踪和管理您的读取 :
// Get unread articles
const unread = await follow.entries.list({
read: false,
limit: 50,
})
// Mark articles as read
await follow.entries.batch.read({
entryIds: ['article-1', 'article-2'],
})
// Save articles to inbox
await follow.entries.inbox.add({
entryId: 'article-123',
note: 'Read later',
})
* AI功率特性
用人工智能增强阅读能力:
// Get article summaries
const summary = await follow.ai.summary({
id: 'article-123',
})
// Chat with AI about your articles
const response = await follow.ai.chat({
messages: [
{ role: 'user', content: 'What are the key trends in this article?' },
],
})
// Get personalized recommendations
const recommendations = await follow.ai.recommendations()
分析与透视
了解你的阅读习惯:
// Get reading statistics
const stats = await follow.reads.stats()
// Track feed performance
const feedAnalytics = await follow.feeds.analytics({
feedId: 'feed-123',
})
设置配置( P)
网络应用程序
import { FollowClient } from '@follow-app/client-sdk'
const follow = new FollowClient({
baseURL: 'https://api.follow.is',
credentials: 'include', // For cookie-based authentication
})
对于Node.js应用程序
import { FollowClient } from '@follow-app/client-sdk'
const follow = new FollowClient({
baseURL: 'https://api.follow.is',
headers: {
Authorization: 'Bearer your-api-token',
},
})
// Or set the token later
follow.setAuthToken('your-api-token')
原生反应
import { FollowClient } from '@follow-app/client-sdk'
const follow = new FollowClient({
baseURL: 'https://api.follow.is',
credentials: 'include',
headers: {
'User-Agent': 'YourApp/1.0.0',
},
})
处理错误
SDK为常见情景提供清晰的错误处理:
import { FollowAPIError, FollowAuthError } from '@follow-app/client-sdk'
try {
const articles = await follow.entries.list()
} catch (error) {
if (error instanceof FollowAuthError) {
// User needs to log in
console.log('Authentication required')
redirectToLogin()
} else if (error instanceof FollowAPIError) {
// Handle API errors (network, server, etc.)
console.log(`Error: ${error.message}`)
showErrorMessage(error.message)
}
}
error.message 是服务器的回答, 适合显示 。 要求的东西被分开
error.request 用于日志和报告:其方法、路径、查询和正文,其数值可认证
用户,例如密码,被替换。 它从来不持有请求的抬头.
特定错误代码
error.serverCode 是服务器答案的代码,其中之一 ExceptionCodeMap,也用于
认证错误, 其 code 实值 AUTH_REQUIRED一个不是API的答案,比如
代理错误页面, 没有 .
import { ExceptionCodeMap, FollowAPIError } from '@follow-app/client-sdk'
try {
await follow.subscriptions.create({ feedId: '41234567890123456' })
} catch (error) {
if (error instanceof FollowAPIError && error.serverCode === ExceptionCodeMap.FeedNoFound) {
console.log('There is no feed with that id')
}
}
配置文件出错代码
更好的奥特 update-user 财务报告和审定财务报表 sign-up/email 回答一个他们拒绝的配置字段 code 名称字段.
更好的 Auth 客户端解决错误而不是丢弃,所以读取 res.error.code数字 :
| 代码 | 外地 | 拒绝值 |
|---|---|---|
HANDLE_ALREADY_TAKEN | handle | 另外一个用户拥有手柄,在任何信件情况下. |
HANDLE_INVALID | handle | 一个非 A-Z, (中文(简体) ), a-z, (中文(简体) ), 0-9 或者说 _。 。 。 . |
HANDLE_INVALID_CHARACTERS | handle | 无法看到的空间或字符, 例如 U+200B。 。 。 . |
HANDLE_TOO_LONG | handle | 超过36个人物. |
NAME_CANNOT_BE_EMPTY | name | 一个空白的名字. |
NAME_TOO_LONG | name | 超过64个角色. |
IMAGE_TOO_LONG | image | 超过256个字符. |
BIO_TOO_LONG | bio | 超过256个字符. |
WEBSITE_TOO_LONG | website | 超过256个字符. |
手柄规则只适用于新的或已更改的手柄:在它们继续保存之前保存的手柄,而保存则按原样寄回. 相邻的空间被修剪,一个空白的手柄可以清除.
常用案例
建立个人 RSS 阅读器
// Set up the client
const follow = new FollowClient({
baseURL: 'https://api.follow.is',
credentials: 'include',
})
// Subscribe to feeds
await follow.subscriptions.create({
url: 'https://blog.openai.com/rss/',
category: 'AI & Technology',
})
// Get latest articles
const latest = await follow.entries.list({
read: false,
limit: 20,
})
// Display articles to user, then mark as read
await follow.entries.batch.read({
entryIds: latest.data.map((article) => article.id),
})
内容校正工具
// Import existing OPML subscription list
await follow.subscriptions.import({ opmlContent })
// Get articles from specific categories
const techNews = await follow.entries.list({
category: 'Technology',
limit: 100,
read: false,
})
// Filter by keywords
const aiArticles = techNews.data.filter(
(article) =>
article.title.toLowerCase().includes('ai') ||
article.content.toLowerCase().includes('artificial intelligence'),
)
// Save important articles to inbox
for (const article of aiArticles) {
await follow.entries.inbox.add({
entryId: article.id,
note: 'AI trend research',
})
}
AI-增强阅读应用程序
// Get user's reading recommendations
const recommendations = await follow.ai.chat({
messages: [
{
role: 'user',
content: 'What are the most important articles I should read today?',
},
],
})
// Get summary of long articles
const longArticles = await follow.entries.list({
read: false,
limit: 10,
})
for (const article of longArticles.data) {
const summary = await follow.ai.summary({
id: article.id,
})
console.log(`${article.title}\nSummary: ${summary.summary}`)
}
许可证
麻省理工学院执照 - 看 自由主义 详细文件.
捐款
我们欢迎捐款! 请看我们的 贡献指南 详细情况如下:
- 建立发展环境
- 测试和起伏
- 提交拉动请求
- 代码样式准则
由美国制造 福罗 团队