[原文链接]http://feclub.cn/post/content/api

一、做什么用的?

第三方应用博客文档(markdown)接口API是给提供给团队成员(本站作者用户)同步博客使用。可以通过调用该API,直接新建、修改、删除本站博客。

二、如何使用?

第1步:获取您的secret_id

登录本站后直接访问: http://mlsfe.biz/dashboard/user/mine ,即可看到:

注意:

  1. 请确保您secret_id的安全,不要被他人获取
  2. secret_id的有效期是一个月,如果失效请重新获取

第2步:调用接口同步博客

以获取博客分类列表为例,(获取博客分类接口说明请参见下文 3.3):

  • shell

      curl -d secret_id=您的secret_id http://mlsfe.biz/api/post/aj_cate_list
  • nodejs:

      var querystring = require('querystring');
      // 可以使用node-fetch创建http.request
      // 需要npm install node-fetch , 文档:https://github.com/bitinn/node-fetch
      var fetch = require('node-fetch');
    
      // 接口URL
      var url = 'http://mlsfe.biz/api/post/aj_cate_list';
      // 接口类型
      var method = 'POST';
      // 请求参数
      var data = {
          secret_id:'您的secret_id',
      };
    
      fetch(url,{
          method:method,
          body:querystring.stringify(data),
          headers:{
              'content-type':'application/x-www-form-urlencoded'
          }
      }).then(function(res){
          return res.json();
      }).then(function(json) {
          console.log(json);
          // 打印出博客分类
      });

三、接口列表

1、 新建或编辑博客

  • 接口URI:

POST http://mlsfe.biz/api/post/aj_edit

  • 参数
Name Type required Description
secret_id String true 您在第一步获取的secret_id
is_new String true 是否新建博客,可选0、1两个值:'0',编辑博客;‘1’,新建博客
id String true 博客的ID,即博客唯一ID,支持数字、大小写字母、下划线、中划线,保存后不可更改
title String true 博客标题,可以是任意字符
image String false 博客主题图片,如果有则显示,目前仅在博客列表页(首页)中显示
from String false 博客来源,博客文章在您的博客网站中的链接
content String true 博客Markwown源码
htmlContent String true 博客markdown编译之后的html内容,用以展示在文档内容页
introContent String true 博客html格式的介绍内容,用以展示再文档列表页
category String true 博客分类的id,文档分类必须从博客分类列表接口中获取

注意

  1. 由于不同博客系统的markdown编译器引擎不一样,所以需要把markdown源码、markdown编译之后html代码、markdown简介都传过来
  2. 下面是一个简单的获取markdown简介的方法,获取markdown编译之后的hrml代码之后,通过jQuery进行解析获取前10个DOM:

     var _getIntroContent = function(html){
         var htmlContent = $(html),result = '';
             for(var i=0;i < 10;i++){
                 if(!htmlContent[i]){break;}
                 if(!htmlContent[i].outerHTML){continue;}
    
                 result += htmlContent[i].outerHTML;
             }
         return result
     }
  • 返回

JSON :

{
    "code":0, // 错误码
    "message":"" // 错误信息
}

例如:

{
   "code":0,
   "message":"文档保存成功"
}

2、删除博客

  • 接口URI:

    POST http://mlsfe.biz/api/post/aj_post_delete

  • 参数

Name Type required Description
secret_id String true 您在第一步获取的secret_id
id String true 要删除的博客ID
  • 返回

JSON :

{
    "code":0, // 错误码
    "message":"" // 错误信息
}

例如:

{
   "code":0,
   "message":"文档保存成功"
}

3、获取博客类型列表

  • 接口URI:

POST http://mlsfe.biz/api/post/aj_cate_list

  • 参数
Name Type required Description
secret_id secret_id true 您在第一步获取的secret_id
  • 返回

JSON :

[{
    "id": "nodejs",// 博客分类的ID
    "name": "Node.js",// 博客分类的类型
    "numb": 2 // 该博客分类下的文章数量
}]

例如:

 [{
    "id": "nodejs",
    "name": "Node.js",
    "_id": "56bf8c6180c391f56d1637b0",
    "numb": 2
 },{
    "id": "fe",
    "name": "Web前端",
    "_id": "56bf8c8b80c391f56d1637b9",
    "numb": 2
 },{
    "id": "native",
    "name": "客户端开发",
    "_id": "56bf8cc480c391f56d1637c2",
    "numb": null
 },{
    "id": "team",
    "name": "团队",
    "_id": "56bf8d0780c391f56d1637d8",
    "numb": 3
 },{
    "id": "php",
    "name": "PHP",
    "_id": "56bf8d6680c391f56d1637ee",
    "numb": 0
 },{
    "id": "doc",
    "name": "使用文档",
    "_id": "56c149fe3134833c64cfe5de",
    "numb": 1
 }]