【问题标题】:Can't subscribe to channel after granting does succeed授予成功后无法订阅频道
【发布时间】: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 个错误。我试过包括和排除一堆配置变量,比如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);

为什么 PHP grant 有效,而 JS subscribe 无效?

【问题讨论】:

    标签: javascript php publish-subscribe pubnub


    【解决方案1】:

    PubNub 状态和访问管理器

    任何时候您在 PubNub 中同时使用 PresenceAccess Manager(所有帐户都免费提供)时,当您授予频道权限时,如果客户是监控状态(在通道上实现状态回调或启用状态 - 取决于 SDK 如何处理)。

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

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

    【讨论】:

    • 我今天从非常快速和良好的 PubNub 支持中发现。文档中没有提到任何类型的 =( 它有效。太好了!我不知道二合一赠款。太好了!已经优化了!谢谢
    • 是的,就是我;)干杯!
    猜你喜欢
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    • 2022-08-09
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    相关资源
    最近更新 更多