我正在使用firebase云端函数创建一个令牌生成器,并且我想使用https触发器来创建令牌,但是我需要在调用url的过程中包含数据。我知道这是可能的,但我不一定知道如何去做。如何使用firebase https触发器功能
我需要这个,所以我可以为我的函数中的某些变量设置值。
所以最终的URL可能看起来像这样的伪代码:
https://tokengen/identity=/room=
这里,身份和房间是两个值我想包括用于variales调用函数时。
所以要重申,
我知道你可以使用请求数据: exports.token = functions.https.onRequest((request, response) => {
,但我怎么包括与HTTPS调用一起的数据,包括作为变量。一个例子将不胜感激。同任何答案,建议或参考一样。
编辑:
这里是更新后的代码,
exports.tokenGenerator = functions.https.onRequest((request, response) => {
const { identity, roomName } = request.query;
const AccessToken = require('twilio').jwt.AccessToken;
const VideoGrant = AccessToken.VideoGrant;
const twilioAccountSid = '1xxxxxxxxxx';
const twilioApiKey = '1xxxxxxxxxx';
const twilioApiSecret = '1xxxxxxxxxx';
function generateToken(identity, roomName) {
const videoGrant = new VideoGrant({
room: roomName
});
const token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
token.addGrant(videoGrant);
token.identity = identity;
return token.toJwt();
}
response.send(token.toJwt());
});
当我使用的url返回Error: could not handle the request
查看这里的例子:https://github.com/firebase/functions-samples/tree/master/delete-unused-accounts-cron它显示了如何包括和访问查询的例子 –