我一直在跟着这个 https://github.com/songz/OpenTokNodeJS
我发布了一个问题,但我想我也会尝试一下。
我已经在这工作了一分钟,似乎无法让它运行。 这是我的错误
TypeError: Object Error: Invalid Key or Secret has no method 'createSession'
at port (/Users/rswain/Desktop/Art/videotok/app.js:42:19)
at callbacks (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:164:37)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:138:11)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:135:11)
at pass (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:173:5)
at Object.router (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:33:10)
at next (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/proto.js:193:15)
at resume (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:65:7)
at SendStream.error (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:80:37)
TypeError: Object Error: Invalid Key or Secret has no method 'createSession'
at port (/Users/rswain/Desktop/Art/videotok/app.js:42:19)
at callbacks (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:164:37)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:138:11)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:135:11)
at pass (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:173:5)
at Object.router (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:33:10)
at next (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/proto.js:193:15)
at resume (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:65:7)
at SendStream.error (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:80:37)
我猜这与我的api密钥有关,说实话,我不是100%,我甚至应该把它放在那里。我尝试过几种方法。首先,我替换了app.js中的行
var OTKEY = process.env.TB_KEY; var OTSECRET = process.env.TB_SECRET;
与
var OTKEY = (my api key);
var OTSECRET = (my secret);
但是当我运行$ node app.js时,没有任何反应,我收到了错误
我也尝试过将密钥和密码添加到package.json文件中,如此
{
"name":"NodeOpenTok",
"version":"0.0.2",
"dependencies":{
"opentok":"44456952",
"express":"7f2ecae114cd4095a1ed689ff63910f1ea79444b",
"ejs":""
}
}
但是我得到了同样的错误。任何想法?
感谢你做这个,看起来很棒,迫不及待地想让它发挥作用!
答案 0 :(得分:3)
我的名字是宋,我相信我可以帮助你。当我编写以下代码时,我只是设置变量OTKEY和OT_SECRET。
var OTKEY = process.env.TB_KEY;
var OTSECRET = process.env.TB_SECRET;
您可以直接替换密钥和密钥:
var OTKEY = "1234";
var OTSECRET = "1abbababaabcabc";
process.env.TB_KEY
和process.env.TB_SECRET
从我的系统环境中提取变量。我这样做是出于安全原因(我不想意外地将我的密钥/秘密推送到github)。要为系统环境设置变量,请打开bash配置文件并添加以下行:
export TB_KEY='1234'
export TB_SECRET='1abbababaabcabc'
同样,设置环境变量不是让代码工作所必需的。最简单的方法是简单地设置变量OTKEY和OTSECRET。
祝你好运!