简体   繁体   English

PubNub存在重复403禁止的错误

[英]PubNub Presence Repeating 403 Forbidden Error

I'm trying to use PubNub presence in my app and I'm getting a repeating forbidden error. 我正在尝试在我的应用中使用PubNub的状态,并且遇到了重复的禁止错误。 I do have the permissions enabled in the PubNub Admin Portal. 我确实在PubNub管理门户中启用了权限。

Here is my subscription code: 这是我的订阅代码:

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);

This is my userConnected callback: 这是我的userConnected回调:

userConnected = (m: any) => {
    var hereNowSettings: pubnub.IHereNowSettings = {
        channel: this.channelString,
        callback: (message: any) => {
            this.channelCount++;
        }

    };

    this.pubnub.here_now(hereNowSettings);
};

I get a repeating error that says 我收到一个重复的错误,说

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)

I don't understand why I'm getting this error. 我不明白为什么会收到此错误。 Can anyone explain this? 谁能解释一下?

UPDATE: 更新:

I added a secret key and grant to my pubnub config: 我添加了一个秘密密钥并授予我的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);
}

However, now I'm getting an error that says 但是,现在我得到一个错误,提示

Missing Secret Key 缺少秘密钥匙

PubNub Access Manager & Granting Permissions PubNub访问管理器和授予权限

If you have Access Manager enabled then your server must grant permission to read on the channel and the presence channel if you are going to subscribe (with presence) on that channel. 如果启用了访问管理器,则服务器要授予权限以在该频道和在线状态频道上进行read (如果您要在该频道上进行订阅(在线状态))。

You said: 你说:

permissions enabled in the PubNub Admin Portal 在PubNub管理门户中启用的权限

... but you do not enable (grant) permissions in the Admin Portal, you grant permission in code using the secret key. ...但是您没有在管理门户中启用(授予)权限,而是使用密钥在代码中授予权限。

See the following links for how to use Access Manager to grant permissions: 有关如何使用Access Manager授予权限的信息,请参见以下链接:

TL;DR (from the links above) You have to grant the read permission on both the channel and its -pnpres channel. TL; DR (来自上面的链接)您必须在通道及其-pnpres通道上都grant 读取权限。 So if you grant read to " chat " then you need to grant read to " chat-pnpres ", if you want to subscribe to presence events on that channel. 因此,如果您要授予对“ chat ”的读取权限 ,那么如果您想订阅该频道上的在线状态事件,则需要授予对“ chat-pnpres ”的读取权限 It also gives you get/setState , herenow and wherenow permissions on the channel ( chat ), too. 它还为您提供get/setStateherenowwherenow通道( chat )的权限。


UPDATE for latest versions of PubNub SDKs 更新最新版本的PubNub SDK

By the way, with current PubNub SDKs, the secret-key gives you all permissions on all channels and channel groups. 顺便说一句,使用当前的PubNub SDK, secret-key可为您提供所有频道和频道组的所有权限。 So do NOT include an auth-key when you init PubNub with a secret-key because the auth-key will override the secret-key with respect to all PubNub requests other than grant by your server. 当你因此不包括身份验证密钥 init PubNub用的密钥 ,因为身份验证密钥将覆盖相对于比其他所有PubNub请求秘密密钥 grant您的服务器。

Secret Key - All Permissions 密钥-所有权限

Anyone with the secretKey can grant and revoke permissions to your app. 具有secretKey的任何人都可以授予和撤消对您的应用程序的权限。 Never let your secretKey be discovered, and to only exchange it / deliver it securely. 永远不要让您的secretKey被发现,而只能安全地交换/交付它。 Only use the secretKey on secure server-side platforms. 仅在安全的服务器端平台上使用secretKey。

Make sure you've granted read permission on the presence channel also. 确保您还授予了在线状态频道的读取权限。

Eg if the channel is my_channel , grant read permission to the my_channel-pnpres presence channel also. 例如,如果通道为my_channel ,则my_channelmy_channel-pnpres存在通道授予读取权限。

More info available here 更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM