[英]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個錯誤。 我已經嘗試過包含和排除一些配置變量,比如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);
.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
?
任何時候您在PubNub中使用Presence和Access Manager (包括所有帳戶免費),當您向頻道授予權限時,如果客戶端要監視在線狀態,您還需要授予對這些頻道的-pnpres
對應的訪問權限(實現存在回調或啟用通道上的存在 - 取決於SDK如何處理它。
$grants = $pubnub->grant(true, true, 'sports,sports-pnpres', $auth_key, 0);
此代碼示例顯示了如何在一次調用中授予多個通道。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.