【发布时间】:2016-07-26 00:02:51
【问题描述】:
我正在尝试在我的应用中使用 PubNub 存在,但我遇到了重复的禁止错误。我确实在 PubNub 管理门户中启用了权限。
这是我的订阅代码:
var initSettings: pubnub.IInitSettings = {
publish_key: "myPubKey",
subscribe_key: "mySubKey",
uuid: "myUUID",
auth_key: "myAuthKey"
};
this.pubnub = PUBNUB(initSettings);
console.log(this.pubnub);
var subscribeSettings: pubnub.ISubscribeSettings = {
channel: "chat",
presence: this.userConnected,
message: this.processMessage
};
this.pubnub.subscribe(subscribeSettings);
这是我的userConnected 回调:
userConnected = (m: any) => {
var hereNowSettings: pubnub.IHereNowSettings = {
channel: this.channelString,
callback: (message: any) => {
this.channelCount++;
}
};
this.pubnub.here_now(hereNowSettings);
};
我收到一个重复的错误提示
pubnub-3.7.14.js:2644 GET http://ps17.pubnub.com/subscribe/mySubKey/chat%2Cchat-pnpres/0/0?uuid=myUUID&pnsdk=PubNub-JS-Web%2F3.7.14 403 (Forbidden)
我不明白为什么会出现此错误。谁能解释一下?
更新:
我添加了一个密钥并授予我的 pubnub 配置:
createPubNubConnections() {
let initSettings: pubnub.IInitSettings = {
publish_key: publishKey,
subscribe_key: subscribeKey,
uuid: uuid,
auth_key: authKey,
secret_key: secretKey
};
this.pubnub = PUBNUB(initSettings);
console.log(this.pubnub);
let subscribeSettings: pubnub.ISubscribeSettings = {
channel: "chat",
presence: this.userConnected,
message: this.processMessage
};
this.pubnub.subscribe(subscribeSettings);
let grantSettings: pubnub.IGrantSettings = {
read: true,
callback: (message: any) => { console.log(message); }
};
this.pubnub.grant(grantSettings);
}
但是,现在我收到一个错误提示
缺少密钥
【问题讨论】:
标签: javascript typescript pubnub