这就是我在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);
有效。我的auth密钥和正确的访问获得了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 {s}。如果我不包含任何origin
,则只有403,不会发生任何事件。
在JS中执行here_now()
工作正常,但uuids
为空,occupancy
为0 :
setInterval(function() {
pubnub.here_now({channel: settings.channel}, function(rsp) {
console.log('here_now', rsp);
});
}, 2000);
.subscribe()
,所以不知道应该做些什么。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
?
答案 0 :(得分:1)
只要您在PubNub中使用Presence和Access Manager(包括所有帐户免费),当您向频道授予权限时,您还需要授予对这些频道的访问权限{{1}如果客户端要监视状态(实现状态回调或在通道上启用状态,则取决于SDK如何处理)。
-pnpres
此代码示例显示了如何在一次通话中授予多个频道。