簡體   English   中英

授予成功后無法訂閱頻道

[英]Can't subscribe to channel after granting does succeed

這就是我在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個錯誤。 我已經嘗試過包含和排除一些配置變量,比如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

PubNub Presence和Access Manager

任何時候您在PubNub中使用PresenceAccess Manager (包括所有帳戶免費),當您向頻道授予權限時,如果客戶端要監視在線狀態,您還需要授予對這些頻道的-pnpres對應的訪問權限(實現存在回調或啟用通道上的存在 - 取決於SDK如何處理它。

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

此代碼示例顯示了如何在一次調用中授予多個通道。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM