nodejs版的有道云API

nodejs版的有道云API

月光魔力鸭

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

因为自己的记录笔记的应用是有道云,又想着把有道云跟自己的小网站联通起来,所以查找了有道云的undefined,然后实现了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 提供的功能,能做的还是比较少的,勉强能使用。

undefined

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

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


感谢支持!

赞赏支持
提交评论
评论信息 (请文明评论)
暂无评论,快来快来写想法...
推荐
产品版本更新的时候经常会有一些数据库的差异,如果版本管理好的话,一步一步升级即可.. 但是如果好久没更新的话,还是有很多不确定的,只能挨着比对表和字段。比对了一次就烦了,写了这么一个工具,查询差异表和字段并给出sql语句。
近期有个小工具,需要使用到本地数据库,想使用sqlite ,本来以为是个手到擒来的活... 没成想卡在了开始上。
前段时间做了个微信小程序反编译的小东西,不过因为功能不全,没加分包处理,正好处理下加上,又考虑到后续可能的更新情况,准备上手增加下更新功能。
最近在折腾的时候又想写less了,但是换框架了,成了thinkjs,考虑到开发阶段一直编译编译less的情况..最终根据middleware的特点实现了一个超级简单的less中间件。
记录下在linux环境下安装phantomjs 的步骤,防止遗忘...
thinkjs框架使用ueditor记录。
从豆瓣转到网易云后,发现了不少好听的歌曲,然鹅..当我想把这些歌拿下来扔车上听的时候发现竟然不允许下载..能听不能下?这不科学,作为一名程序猿,必然要迎难而上啊.