我尝试在我的应用中使用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);
}
但是,现在我收到的错误是
缺少密钥
答案 0 :(得分:1)
如果您启用了Access Manager,那么如果您要在该频道上订阅(有状态),您的服务器必须授予频道和状态频道read
的权限。
你说:
在PubNub管理员门户中启用权限
...但您没有在管理门户中启用(授予)权限,您使用密钥在代码中授予权限。
有关如何使用Access Manager授予权限,请参阅以下链接:
答案 1 :(得分:0)