3

我一直在关注这个 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":""
    }
}

但我得到同样的错误。有任何想法吗?

谢谢你做这个,看起来很棒,等不及要让它工作了!

4

1 回答 1

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_KEYprocess.env.TB_SECRET从我的系统环境中提取变量。出于安全原因,我这样做(我不想不小心将我的密钥/秘密推送到 github)。要为您的系统环境设置变量,请打开您的 bash 配置文件并添加以下行:

export TB_KEY='1234'
export TB_SECRET='1abbababaabcabc' 

同样,不需要设置环境变量来让您的代码正常工作。最简单的方法是简单地设置变量 OTKEY 和 OTSECRET。

祝你好运!

于 2013-11-27T05:40:30.827 回答