很抱歉,我已经观看了Jennifer Person 的所有七个视频,阅读了文档,并完成了教程,但我仍然不知道如何编写我的函数。我正在尝试编写一个获取 IBM Watson Speech-to-text 令牌的函数,该令牌是通过以下 CURL 脚本获得的:
curl -X GET --user username:password --output token
"https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api"
即,向 URL 发送 HTTP GET 请求,提供我的用户名和密码,然后将输出写入文件/javascript/services/token。
这是我对功能的猜测。身份验证触发器包装 Nodejs HTTP GET 请求和 NodeJs 文件 save fs.writefile。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.getWatsonToken = functions.auth.user().onCreate(event => { // authentication trigger
var https = require('https'); // Nodejs http.request
var options = {
host: 'stream.watsonplatform.net',
path: '/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api',
username: groucho,
password: swordfish
};
callback = function(response) {
response.on('end', function () {
console.log(response);
fs.writeFile("/javascript/services/token", response);
});
}
http.request(options, callback).end();
});