Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Twilio聊天API-获取分页消息列表(pageNo,pageLimit)_Node.js_Twilio_Twilio Api - Fatal编程技术网

Node.js Twilio聊天API-获取分页消息列表(pageNo,pageLimit)

Node.js Twilio聊天API-获取分页消息列表(pageNo,pageLimit),node.js,twilio,twilio-api,Node.js,Twilio,Twilio Api,我无法使用pageNumber和pageSize获取邮件列表。 它每次都返回整个结果。 有没有办法按pageSize和pageNumber查询数据 twilioClient.chat.services(TWILIO_CHAT_SERVICE_SID) .channels(req.params.id) .messages .list({ pageSize: 2, page: 2 }, (error, messages) => {

我无法使用pageNumber和pageSize获取邮件列表。 它每次都返回整个结果。 有没有办法按pageSize和pageNumber查询数据

twilioClient.chat.services(TWILIO_CHAT_SERVICE_SID)
    .channels(req.params.id)
    .messages
    .list({
        pageSize: 2,
        page: 2
    }, (error, messages) => {
        if (error) {
            return res.status(error.status).json({
                message: 'Problem in getting messages',
                error: error
            });
        }

        if (Utility.isEmptyObject(messages)) {
            return res.status(404).send('Messages not found');
        }

        res.status(200).json({
            message: 'Messages retrieved sucessfully',
            docs: messages
        });
    });
我想按pageSize和pageNumber查询结果。同时,如果我发送RESTAPI调用,它将返回带有pageSize的结果,但pageNumber在这里也不起作用

let limitCount = parseInt(req.query.limit > 0 ? req.query.limit : 10); // limitValue
let pageNo = parseInt(req.query.pageNo > 0 ? req.query.pageNo : 0);

let options = {
    method: 'GET',
    url: 'https://chat.twilio.com/v2/Services/IS/Channels/' +
        'CH2f/Messages?Page=' + pageNo + '&PageSize=' + limitCount,
    headers:
    {
        'cache-control': 'no-cache',
        Authorization: 'Token'
    }
};

request(options, function (error, response, body) {

    console.log(body);

    if (error) {
        //console.error("There was an error loading the channels.", error);
        return res.status(error.status).json({
            message: 'Problem in getting messages',
            error: error
        });
    }

    if (Utility.isEmptyObject(response)) {
        return res.status(404).send('Messages not found');
    }

    res.status(200).json({
        status: 'Messages retrieved sucessfully',
        messages: JSON.parse(body)
    });
});

非常感谢您的帮助。

这里是Twilio开发者福音传道者

Twilio资源不支持基于页码的分页。相反,一页数据将包括
下一页\u uri
上一页\u uri
属性。您可以使用
PageSize
参数控制页面大小

使用这些库时,可以让它们自动分页。例如:

twilioClient.chat.services(TWILIO_CHAT_SERVICE_SID)
  .channels(req.params.id)
  .messages
  .list({
    limit: 400,
    pageSize: 100
  });
最终将调用API 4次,以返回总共400条消息


您可以阅读更多关于

的信息,您可能希望从问题中删除您的访问令牌。好的。这不是一个有效的令牌。另外,在使用nodejs库时,我无法获取下一页、上一页和其他元数据字段,但在使用http请求时,所有字段都会显示。您可以使用
page
方法,该方法将返回