Firebase云函数错误-函数返回了未定义的、预期的Promise或值



当创建新文档时,我正试图用谷歌云功能在Appsflyer上记录购买事件,但我遇到了这个错误。

我所有的插值在日志中似乎都很好。我的功能是

exports.validatePaymentAppsflyer = functions.firestore.document('_orderFinishedSuccessfully/{id}').onCreate((snap, context) => {
console.log(snap, context);
const newValue = snap.data();
const requestData = newValue;
console.log(requestData.platform);
if ( requestData.platform === 'ios' ) {
appId = 'id1303984176';                
} else {
appId = 'com.myapp';                
}
var request = require("request");
var options = { method: 'POST',
url: 'https://api2.appsflyer.com/inappevent/' + appId,
headers: 
{ 
"authentication": 'M762jn36Bb7kBt70jNdtrU',
'Content-Type': 'application/json' 
},
body: 
{ appsflyer_id: requestData.appsflyerId,
customer_user_id: requestData.customerUserId,
eventName: 'af_purchase',
eventValue: {
"af_revenue":requestData.totalTTC,
"af_order_id":requestData.orderId,
"af_city":requestData.city,
"af_date_b":requestData.date
},
eventCurrency: 'EUR',
ip: requestData.userIp,
eventTime: requestData.date,
af_events_api: 'true' },
json: true };
console.log(options);

request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
});

我需要你的帮助

云函数应该返回一些有意义的东西,通常您希望返回一个Promise。这样引擎就会知道异步操作已经完成,不必等待超时。

要修复代码,只需返回Promise:

return new Promise((resolve, reject) => {
request(options, function (error, response, body) {
if (error) reject(error);
else resolve(response);
});
});

相关内容

  • 没有找到相关文章

最新更新