nodejs版的有道云API

nodejs版的有道云API

月光魔力鸭

2018-09-12 10:10 阅读 876 喜欢 0 有道云 API nodejs

因为自己的记录笔记的应用是有道云,又想着把有道云跟自己的小网站联通起来,所以查找了有道云的API,然后实现了nodejs版本的sdk.

目前实现的比较简单,很多实现都没有进行优化,可能会有些BUG⊙﹏⊙‖∣,主要是提供给大家可以相互借鉴

安装

npm i ydnote

使用

//获取token
var YNote = require('ydnote');

var youdao = new YNote({
    //申请的client id
    clientId : '',
    //申请的client secret
    clientSecret : '',
    //应用回调地址
    oauthUrl : ''
});
//获得有道授权登录地址
console.log(youdao.getOAuthUrl());
//然后根据授权地址回调后返回的code,获得token
youdao.getToken('75875d373ab5e9e8b46f32301169bc19').then(function(token){
    console.log(token);
}).catch(function(e){
    console.log(e.status);
    console.log(e.message);
})

函数使用

再获得token后,将token保存,然后在调用函数的时候即可传token获取相关的信息。

获取用户信息

youdao.getUserInfo(token).then(function(userInfo){
    console.log('获得用户信息:'+userInfo.user)
}).catch(function(e){
    console.log(e.status);
    console.log(e.message);
})

获得所有的笔记本信息

youdao.getAllNotebook(token).then(function( bookList ){
    console.log(`笔记本个数有:${bookList.length}`);
}).catch(function(e){
    console.log(e.status);
    console.log(e.message);
    console.log(e.response.text)
})

获得笔记本内的所有笔记信息

youdao.getNoteOfBook(token,'/513BEFD144B84F28923AE83B09BB3DF2').then(function( noteList ){
    console.log(`笔记个数有:${noteList.length}`);
}).catch(function(e){
    console.log(e.status);
    console.log(e.message);
})

创建笔记本和删除

youdao.createNotebook(token,'API创建笔记本').then(function(rsObj){
    console.log('笔记本创建成功:'+rsObj.path);
    return youdao.deleteNotebook(token,rsObj.path);
}).then(function(){
    console.log('笔记本删除成功')//删除无返回值
}).catch(function(e){
    console.log(e.status);
    console.log(e.message);
    console.log(e.response.text);
})

创建笔记

youdao.createNote(token,{
    content : '<html><body><p style="color:red">笔记创建测试</p></body></html>',
    // content : 'aaa',
    title : '测试'
}).then(function(rsObj){
    console.log(rsObj);//返回保存后的路径和相关信息
})
.catch(function(e){
    console.log(e.status);
    console.log(e.message);
    console.log(e.response.text);
})

获取笔记信息

youdao.getNote(token,notePath)
.then(function(rsObj){
  console.log(rsObj);//获得笔记的详细信息
})
.catch(function(e){
    console.log(e.status);
    console.log(e.message);
    console.log(e.response.text);
})

修改笔记

youdao.updateNote(token,{
  path : rsObj.path,//笔记的path
  content : '修改'
})
.then(function(rsObj){
    console.log(rsObj);//该函数无返回值
})
.catch(function(e){
    console.log(e.status);
    console.log(e.message);
    console.log(e.response.text);
})

移动笔记

youdao.moveNote(token,rsObj.path,'/513BEFD144B84F28923AE83B09BB3DF2')
.then(function(rsObj){
    console.log(rsObj);//返回移动后的路径
})
.catch(function(e){
    console.log(e.status);
    console.log(e.message);
    console.log(e.response.text);
})

删除笔记

youdao.deleteNote(token,rsObj.path)
.then(function(rsObj){
    console.log(rsObj);//删除无返回值
})
.catch(function(e){
    console.log(e.status);
    console.log(e.message);
    console.log(e.response.text);
})

分享笔记

youdao.publishNote(token,rsObj.path);
.then(function(rsObj){
    console.log(rsObj);//返回分享后生成的URL
})
.catch(function(e){
    console.log(e.status);
    console.log(e.message);
    console.log(e.response.text);
})

文件上传

youdao.upload(token,__dirname+'/test.js')
.then(function(rsObj){
    console.log(rsObj);//返回上传后的路径
})
.catch(function(e){
    console.log(e);
})

下载文件

youdao.download(token,'https://note.youdao.com/yws/open/resource/download/20114/140BC634A1D9455DAC1E0BFBBD7894C5','/home/test.js')
.then(function(rs){
    console.log(rs);//下载完成
})
.catch(function(e){
    console.log(e);
})

以上是目前有道云笔记OpenApi 提供的功能,能做的还是比较少的,勉强能使用。

github地址

如果本文章有帮助到你..麻烦给个小星星啦~ 土豪,请随意..

转载请注明出处: https://chrunlee.cn/article/youdaonote-api-nodejs.html


感谢支持!

赞赏支持
提交评论
评论信息 (请文明评论)
暂无评论,快来快来写想法...
推荐
最近由于系统需要一些数据进行测试,但是正常的流程都是下载pdf ,打印pdf,然后通过涂写答题卡,将涂写的扫描上传..太麻烦了,想做成简单点,通过程序直接生成..卡在了pdf转图片上,今天抽空找了下库,通过gm可以将pdf转为图片,起码第一步已经实现了,后边的涂学号之前已经做过了。
最近看到知乎上一话题:微信公众号文章里的视频怎么下载?。看还是有很多人推荐啥工具啊,很是捉急,当然本次的主题也是通过程序来获取内容,但是目前来说仅仅是娱乐吧。
docker镜像中的puppeteer安装
介绍几个日常开发中常用的几个小工具: anywhere / anywhere-auth / watchlessc / changeext
前段时间帮朋友下歌放在车上听..结果好多都是ncm格式,伤心 ,搜索了下发现基本上这格式解密有好多昂,可惜UI我都不太想要..决定抄一下,自己做一个。 这里先记录下核心代码,回头补充个UI 做个小程序。
记录下通过nodejs调用imagemagick 的时候发现的一个错误,command failed -- crop .
最近有接触到针对二维码进行识别的功能,然后对图片进行位置纠正、二维码扫描,并将数据进行整理。以下是通过nodejs做的,相对简单一些,没有太过严格,识别率也不是很高大约80%左右
在使用marked来做md解析的时候,部分解析规则可能并不是很如意,比如说,我在md中写了a标签,但是这些标签都是在当前页面替换的,而我想要的是新打开窗口。