Giter VIP home page Giter VIP logo

Comments (9)

mazhe-nerd avatar mazhe-nerd commented on July 28, 2024

不需要拿token哈,直接语义化调用api就好

from node-sdk.

holdmycat avatar holdmycat commented on July 28, 2024

不需要拿token哈,直接语义化调用api就好

我如果要导出一个电子表格, 那么参数里面就需要填写tenantAccessToken.

client.drive.exportTask.get({
path: {
ticket: '7281281080657264644',
},
params: {
token: 'PbgysKgBKho6iJt6fytcpsaSncg',
},
},
lark.withTenantToken("t-g1049lm9NM75KRX3OVSJA4C5IKZWPLDU76LOPGEK")
).then(res => {
console.log(res);
});

这个tenantAccessToken不能写死,会过期。我不拿token,如果导出电子表格呢?

from node-sdk.

mazhe-nerd avatar mazhe-nerd commented on July 28, 2024

token内部会自动获取,不需要手动拿。new完client后,直接这样调用:
client.drive.exportTask.get({
path: {
ticket: '7281281080657264644',
},
params: {
token: 'PbgysKgBKho6iJt6fytcpsaSncg',
},
},

from node-sdk.

holdmycat avatar holdmycat commented on July 28, 2024

token内部会自动获取,不需要手动拿。new完client后,直接这样调用: client.drive.exportTask.get({ path: { ticket: '7281281080657264644', }, params: { token: 'PbgysKgBKho6iJt6fytcpsaSncg', }, },

这个项目和飞书开放平台服务器api文档是关联的吗?对于使用者,刚开始接触我目前只知道可以通过这个平台文档来学习使用。平台文档的示例代码这么写会给开发者很困惑

from node-sdk.

mazhe-nerd avatar mazhe-nerd commented on July 28, 2024

了解~感谢同学反馈。因为调试台页面中已经拿了一遍token,因此示例代码中使用已经存在的这个token,方便copy代码后可以跑通。示例中对这点加了注释,产生困惑的原因可能是这块没有表达清楚,我们想想怎么优化一下。
image

可以阅读一下sdk的readme哈,比较清楚:https://github.com/larksuite/node-sdk/blob/main/README.zh.md

from node-sdk.

holdmycat avatar holdmycat commented on July 28, 2024

。。。。,我也是醉了,飞书平台api文档大家感受一下灵魂就好,不要copy,全是坑。把disableTokenCache: true在new lark.Client里面注释掉就可以了。

const client = new lark.Client({
appId: 'cli_xxxxxxxx',
appSecret: 'xxxxxxxx',
// disableTokenCache为true时,SDK不会主动拉取并缓存token,这时需要在发起请求时,调用lark.withTenantToken("token")手动传递
// disableTokenCache为false时,SDK会自动管理租户token的获取与刷新,无需使用lark.withTenantToken("token")手动传递token
//disableTokenCache: true
});

client.drive.exportTask.create({
data: {
file_extension: 'xlsx',
token: 'xxxxxxxx',
type: 'sheet',
},
},
lark.withTenantToken("")
).then(res => {
console.log(res);
});

from node-sdk.

holdmycat avatar holdmycat commented on July 28, 2024

了解~感谢同学反馈。因为调试台页面中已经拿了一遍token,因此示例代码中使用已经存在的这个token,方便copy代码后可以跑通。示例中对这点加了注释,产生困惑的原因可能是这块没有表达清楚,我们想想怎么优化一下。 image

可以阅读一下sdk的readme哈,比较清楚:https://github.com/larksuite/node-sdk/blob/main/README.zh.md

现在我的诉求是下载一个线上的电子表格,

client.drive.exportTask.create({
data: {
file_extension: 'xlsx',
token: 'xxxxxxxxxxxx',
type: 'sheet',
},
}
).then(res => {
console.log(res);
client.drive.exportTask.get({
path: {
ticket: res.data.ticket
},
params: {
token: 'PbgysKgBKho6iJt6fytcpsaSncg',
},
}
).then(res => {
console.log(res);
});
});

我拿到的ticket:7281506777802358788。 我在飞书平台调试台拿到的ticket:7281506655445991428。结果不一样,然后我在通过拿到的ticket去调用 client.drive.exportTask.get, 结果是
{ code: 0, data: { ticket: '7281506777802358788' }, msg: 'success' }
{
code: 0,
data: {
result: {
file_extension: '',
file_name: '',
file_size: 0,
file_token: '',
job_error_msg: '',
job_status: 2,
type: ''
}
},
msg: 'success'
}

from node-sdk.

holdmycat avatar holdmycat commented on July 28, 2024

了解~感谢同学反馈。因为调试台页面中已经拿了一遍token,因此示例代码中使用已经存在的这个token,方便copy代码后可以跑通。示例中对这点加了注释,产生困惑的原因可能是这块没有表达清楚,我们想想怎么优化一下。 image

可以阅读一下sdk的readme哈,比较清楚:https://github.com/larksuite/node-sdk/blob/main/README.zh.md

如果我在new client的时候,将disableTokenCache:true打开,就会提示一下错误:
[error]: [
[
{
message: 'Request failed with status code 400',
config: [Object],
request: [Object],
response: [Object]
},
{
code: 99991661,
msg: 'Missing access token for authorization. Please make a request with token attached.',
error: [Object]
}
]
]

from node-sdk.

mazhe-nerd avatar mazhe-nerd commented on July 28, 2024

现在我的诉求是下载一个线上的电子表格,

client.drive.exportTask.create({ data: { file_extension: 'xlsx', token: 'xxxxxxxxxxxx', type: 'sheet', }, } ).then(res => { console.log(res); client.drive.exportTask.get({ path: { ticket: res.data.ticket }, params: { token: 'PbgysKgBKho6iJt6fytcpsaSncg', }, } ).then(res => { console.log(res); }); });

我拿到的ticket:7281506777802358788。 我在飞书平台调试台拿到的ticket:7281506655445991428。结果不一样,然后我在通过拿到的ticket去调用 client.drive.exportTask.get, 结果是 { code: 0, data: { ticket: '7281506777802358788' }, msg: 'success' } { code: 0, data: { result: { file_extension: '', file_name: '', file_size: 0, file_token: '', job_error_msg: '', job_status: 2, type: '' } }, msg: 'success' }

这个用法是对的,ticket应该是每次调用接口都会生成一个新的

from node-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.