可以't在授予成功后订阅频道

Can't subscribe to channel after granting does succeed

本文关键字:成功 频道 可以      更新时间:2023-09-26

这就是我在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响应,其中包含我的auth密钥和正确的访问权限。

然后我在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);
  }
});

并且spwans每秒大约有10403个错误。我尝试过包括和排除一堆配置变量,比如uuidauth_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管理控制台中禁用Access Manager"修复"了它,但显然我需要访问管理
  • 我想我已经跟上了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不能工作?

PubNub存在和访问管理器

任何时候,当您在PubNub中将Presence与Access Manager(所有帐户都免费提供)一起使用时,当您向频道授予权限时,如果客户端要监视Presence,则还需要授予对这些频道的-pnpres对应方的访问权限(在频道上实现Presence回调或启用Presence-取决于SDK如何处理)。

$grants = $pubnub->grant(true, true, 'sports,sports-pnpres', $auth_key, 0);

此代码示例显示如何在一次调用中授予多个通道。