[英]PubNub Presence Repeating 403 Forbidden Error
我正在嘗試在我的應用中使用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);
}
但是,現在我得到一個錯誤,提示
缺少秘密鑰匙
如果啟用了訪問管理器,則服務器要授予權限以在該頻道和在線狀態頻道上進行read
(如果您要在該頻道上進行訂閱(在線狀態))。
你說:
在PubNub管理門戶中啟用的權限
...但是您沒有在管理門戶中啟用(授予)權限,而是使用密鑰在代碼中授予權限。
有關如何使用Access Manager授予權限的信息,請參見以下鏈接:
TL; DR (來自上面的鏈接)您必須在通道及其-pnpres通道上都grant
讀取權限。 因此,如果您要授予對“ chat ”的讀取權限 ,那么如果您想訂閱該頻道上的在線狀態事件,則需要授予對“ chat-pnpres ”的讀取權限 。 它還為您提供get/setState
, herenow
和wherenow
通道( chat )的權限。
順便說一句,使用當前的PubNub SDK, secret-key
可為您提供所有頻道和頻道組的所有權限。 當你因此不包括身份驗證密鑰 init
PubNub用的密鑰 ,因為身份驗證密鑰將覆蓋相對於比其他所有PubNub請求秘密密鑰 grant
您的服務器。
具有secretKey的任何人都可以授予和撤消對您的應用程序的權限。 永遠不要讓您的secretKey被發現,而只能安全地交換/交付它。 僅在安全的服務器端平台上使用secretKey。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.