go-ynote 是有道云笔记开放平台 API 的 Go SDK。
- 建立一个
*YnoteClient
对象,设置开发者 token/secret.
yc := ynote.NewOnlineYnoteClient(ynote.Credentials{
Token: "****",
Secret: "****"})
- 如果还没获得
AccToken
(存取令牌),如下方式得到:
tmpCred, err := yc.RequestTemporaryCredentials()
if err != nil {
return
}
fmt.Println("Temporary credentials got:", tmpCred)
authUrl := yc.AuthorizationURL(tmpCred)
// Let the end-user access this URL of authUrl using a browser,
// authorize the request, and get a verifier.
verifier := ... // Ask the end-user for the verifier
accToken, err := yc.RequestToken(tmpCred, verifier)
if err != nil {
return
}
// save the accToken for further using.
- 之后只要把保存下来的
AccToken
设置到yc
的AccToken
域就可以了(RequestToken
如果成功会自动设置AccToken
域)
yc.AccToken = readAccToken()
- 使用
yc
的操作方法,如UserInfo
/ListNotebooks
等
demo 程序 是一个云笔记的控制台程序,演示了所有 API 的用法。实际使用时,请替换着里面的 token。
BSD license.