【发布时间】:2015-11-25 15:44:41
【问题描述】:
这就是我在 PHP 中所做的:
$pubnub = new Pubnub(array(
'subscribe_key' => '<SUBSCRIBE_KEY>',
'publish_key' => '<PUBLISH_KEY>',
'secret_key' => '<SECRET_KEY>',
'uuid' => $uuid,
));
$grants = $pubnub->grant(true, true, $channel, $auth_key, 0);
这行得通。我使用我的身份验证密钥和正确的访问权限收到 200 响应。
然后我在 JS 中这样做:
var pubnub = PUBNUB.init({
auth_key: settings.auth_key,
subscribe_key: settings.subscribe_key,
publish_key: settings.publish_key,
uuid: settings.uuid,
});
pubnub.subscribe({
channel: settings.channel,
// auth_key: settings.auth_key,
// uuid: settings.uuid,
presence: function(m) {
console.log('presence', m);
},
message: function(m) {
console.log('message', m);
}
});
每秒会产生大约 10 403 个错误。我试过包括和排除一堆配置变量,比如uuid和auth_key,但我得到的只是很多403。
如果我包含origin: 'pubsub.pubnub.com',presence 事件会触发一次或两次,但仍然是一大堆 403。如果我不包含任何 origin,则只有 403,没有事件。
在 JS 中执行 here_now() 可以正常工作,但 uuids 为空,occupancy 为 0:
setInterval(function() {
pubnub.here_now({channel: settings.channel}, function(rsp) {
console.log('here_now', rsp);
});
}, 2000);
- 在 PubNub 管理控制台中禁用访问管理器“修复”它,但显然我需要访问管理
- 我想我已经非常准确地关注了https://www.pubnub.com/docs/web-javascript/pam-security,但没有任何效果。
-
https://www.pubnub.com/developers/tutorials/access-manager/ 甚至没有提到
.subscribe(),所以不知道应该怎么做。 - 要求订阅(10x/秒)的 JS URL 是
http://ps9.pubnub.com/subscribe/<SUBSCRIBE_KEY>/<CHANNEL>%2C<CHANNEL>-pnpres/0/0?uuid=<UUID>&auth=<AUTH_KEY>&pnsdk=PubNub-JS-Web%2F3.7.16
为什么 PHP grant 有效,而 JS subscribe 无效?
【问题讨论】:
标签: javascript php publish-subscribe pubnub