簡體   English   中英

PubNub存在重復403禁止的錯誤

[英]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);
}

但是,現在我得到一個錯誤,提示

缺少秘密鑰匙

PubNub訪問管理器和授予權限

如果啟用了訪問管理器,則服務器要授予權限以在該頻道和在線狀態頻道上進行read (如果您要在該頻道上進行訂閱(在線狀態))。

你說:

在PubNub管理門戶中啟用的權限

...但是您沒有在管理門戶中啟用(授予)權限,而是使用密鑰在代碼中授予權限。

有關如何使用Access Manager授予權限的信息,請參見以下鏈接:

TL; DR (來自上面的鏈接)您必須在通道及其-pnpres通道上都grant 讀取權限。 因此,如果您要授予對“ chat ”的讀取權限 ,那么如果您想訂閱該頻道上的在線狀態事件,則需要授予對“ chat-pnpres ”的讀取權限 它還為您提供get/setStateherenowwherenow通道( chat )的權限。


更新最新版本的PubNub SDK

順便說一句,使用當前的PubNub SDK, secret-key可為您提供所有頻道和頻道組的所有權限。 當你因此不包括身份驗證密鑰 init PubNub用的密鑰 ,因為身份驗證密鑰將覆蓋相對於比其他所有PubNub請求秘密密鑰 grant您的服務器。

密鑰-所有權限

具有secretKey的任何人都可以授予和撤消對您的應用程序的權限。 永遠不要讓您的secretKey被發現,而只能安全地交換/交付它。 僅在安全的服務器端平台上使用secretKey。

確保您還授予了在線狀態頻道的讀取權限。

例如,如果通道為my_channel ,則my_channelmy_channel-pnpres存在通道授予讀取權限。

更多信息在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM