繁体   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