Typecho blog API for Nodejs 发布!

插件开发及发布

版主: woniou

回复
gogobody
帖子: 35
注册时间: 2020年 1月 13日 18:11

Typecho blog API for Nodejs 发布!

帖子 gogobody »

Typecho blog API 是一个nodejs编写的typecho 博客api库
目前支持的api有:

getUsersBlogs 获取博客信息
getRecentPosts 获取最近的num条博客
getCategories 获取分类
getPost 获取博文详情
editPost 编辑、更新博文
newPost 发布新的博文
deletePost 删除博文
newMediaObject 上传媒体
注意
使用强需要在typecho的基本设置里打开XMLRPC 接口。
并在控制台->个人设置->撰写设置 确定是否在 XMLRPC 接口中使用 Markdown 语法,这会影响到getPost接口是否返回markdown还是富文本。

已知问题:

typecho 如果使用了AutoTags插件,则post的mt_keywords为必填字段
果使用了handsome插件,则必须先去插件->搜索设置里构建索引
如果需要上传附件,需要保证usr/目录下有uploads文件夹且具有可写入权限
地址:
https://github.com/gogobody/typecho-api ... /README.md

安装
npm i typecho-api

举例


const Typechoblog = require('typecho-api');
const metaWeblog = new Typechoblog('', '', '');
var blogid, postid;
var post = {
title:"new post", //title
description:"##make down", //content
// wp_slug: "测试slug", //id?
// mt_text_more: "mt_text_more", //"Read more"
// wp_password: "",
mt_keywords: "测试tag", //关键词
categories: ['随便写写'],//categories
// dateCreated:"dateCreated", //创建时间
// mt_allow_comments:1, //允许评论
// mt_allow_pings:1,
// post_status:'publish',//'publish'

};



//
//getUsersBlogs
metaWeblog.getUsersBlogs(1)
.then(blogInfos => {
console.log('\n Method response for \'getUsersBlogs\': ');
console.log(blogInfos);
blogid = blogInfos[0].blogid;

// getCategories
metaWeblog.getCategories(blogid)
.then(categories => {
console.log('\n Method response[0] for \'getCategories\': ');
console.log(categories[0]);
});

//getRecentPosts
metaWeblog.getRecentPosts(blogid, 1)
.then(posts => {
console.log('\n Method response for \'getRecentPosts\': ');
// console.log(posts);
postid = posts[0].postid;

// getPost
metaWeblog.getPost(postid)
.then(post => {
console.log('\n Method response for \'getPost\': ');
// console.log(post);

// editPost
post.description = '##makre \r\n' + post.description;
metaWeblog.editPost(postid, post, true)
.then(success => {
console.log('\n Method response for \'editPost\': ');
console.log(success);
}).catch(error => {
console.log(error)
});
});
});


// newPost
var post = {
title: 'New Post1',
description: 'Post created by `Typechoblog API` on ' + Date(),
categories: ['随便写写'],
mt_keywords: "测试tag",
};
metaWeblog.newPost(blogid, post, true)
.then(newPostId => {
console.log('\n Method response for \'newPost\': ');
console.log(newPostId);

// deletePost
metaWeblog.deletePost(1, newPostId, true)
.then(success => {
console.log('\n Method response for \'deletePost\': ');
console.log(success);
});
}).catch(error => {
console.log(error)
});

// //newMediaObject
// var fs = require("fs");
// var imageFile = fs.readFileSync('test.jpg');
// var media = {
// name: 'test.jpg',
// type: 'image/jpg',
// bytes: new Buffer.from(imageFile, 'binary')
// };
// metaWeblog.newMediaObject("1", media)
// .then(urlData => {
// console.log('\n Method response for \'newMediaObject\': ');
// console.log(urlData);
// });

//
})
.catch(error => {
console.error(error);
});
weich
帖子: 174
注册时间: 2018年 4月 6日 07:48
联系:

Re: Typecho blog API for Nodejs 发布!

帖子 weich »

不知道干嘛用的…用来做客户端?
gogobody
帖子: 35
注册时间: 2020年 1月 13日 18:11

Re: Typecho blog API for Nodejs 发布!

帖子 gogobody »

weich 写了:不知道干嘛用的…用来做客户端?

正在做一个文章发布器,支持多平台
tssz
帖子: 28
注册时间: 2013年 3月 18日 14:13
联系:

Re: Typecho blog API for Nodejs 发布!

帖子 tssz »

viewtopic.php?f=6&t=11871
这里有个安卓app
回复