429-{“状态”:“错误”,“消息”:“达到Api最大rps”}},同时向多聊天sendFlow API发送请求

问题描述 投票:0回答:1

我正在尝试使用其API将CustomField设置为Manychat订户。他们的API的链接是:

https://api.manychat.com/swagger#/Subscriber/post_fb_subscriber_setCustomFieldByName

下面是请求代码:

   var rp = require("request-promise");
   var config = require("./../campaign_config.json");

module.exports = { setWaybillForUser :  async function setWaybillForUser(userid,waybill,dbRef){

        var options = { method: 'POST',
          uri: 'https://api.manychat.com/fb/subscriber/setCustomFieldByName',
          headers: 
           {'Cache-Control': 'no-cache',
             Accept: '*/*',
             Authorization: config.Manychat_token,  
             'Content-Type': 'application/json' },
          body: 
           { subscriber_id: parseInt(userid),
             field_name: 'waybill',
             field_value: waybill },
          json: true };

        try {
        const response = await rp(options);
        console.log(response);
        if (response.status == "success") {
            return dbRef.child('datanode').child(userid).update({
                "Order_Status": 3
            }).then(function () {
                //do nothing.
            }).catch(function (error) {
                console.log(error);
            });
        }
    }
    catch (err) {
        console.log(err.message);
    }
    }
};

我多次调用此函数,因为有许多要为其运行该功能的订阅者。被调用的代码是:

dbRef.child("subData").once('value').then(function(snapshot){
        var data = snapshot.val();
        var keys = Object.keys(data);

        let promiseArray = [];
        let orderStatusArr =[];
        for(let i=0; i< keys.length; i++){

                    var order_status =  data[keys[i]].Order_Status;
                    var subid =  data[keys[i]].UserID;
                    var waybill =  data[keys[i]].Waybill_Number;
                    if(order_status == 1){
                        orderStatusArr.push({
                            "Order_Status":order_status,
                            "UserID": subid,
                            "Waybill_Number":waybill
                        });
                    }
        }

        for(let i=0; i<orderStatusArr.length;i++){
            var order_status =  orderStatusArr[i].Order_Status;
            var subid =  orderStatusArr[i].UserID;
            var waybill =  orderStatusArr[i].Waybill_Number;

            promiseArray.push(setWaybillsForUser.setWaybillForUser(subid,waybill,dbRef));
        }

        Promise.all(promiseArray).then(() => {
            // all done here
            response.send("success");
        }).catch(function(err) {
            console.log(err.message); 
          });

    })

当我运行代码时-它记录了某些请求的成功,同时为其他请求抛出了成功。一次它能够成功为大约10个订阅者运行代码。

node.js api google-cloud-functions facebook-chatbot
1个回答
1
投票

来自this page

API调用数量是否有限制?

[每秒仅对POST方法有一个请求限制(每页):

  1. / fb / send / sendFlow,/ fb / send / sendContent-25 RPS;
  2. / fb / subscriber / addTag,/ fb / subscriber / removeTag,/ fb / subscriber / setCustomField-10 RPS

因此,从您所发布的症状来看,似乎适用第二条规则

© www.soinside.com 2019 - 2024. All rights reserved.