【问题标题】:TypeError: Cannot read property 'userId' - sendbirdTypeError:无法读取属性'userId' - sendbird
【发布时间】:2017-10-11 23:01:00
【问题描述】:

我正在尝试使用群组频道在 2 个 sendbird 用户之间创建一个频道。到目前为止,我的实现是

<script type="text/javascript">
    function chatInit(){
        var sb = new SendBird({
            appId: 'my app id'
         });

    sb.connect('test user','access token of user', function(user, error) {
    console.log(error);

    }); 
    var userIds = ['another user'];
    var name ="name of channel";
    sb.GroupChannel.createChannelWithUserIds(userIds, true, name ,'', '', function(channel, error) {
             if (error) {
        console.error(error);
    return;
}

});

}
</script>

我在控制台上收到以下错误

SendBird.min.js:6 Uncaught TypeError: Cannot read property 'userId' of null
at Function.GroupChannel.createChannelWithUserIds 

我错过了什么,请指导我完成整个过程。 我们将不胜感激。

【问题讨论】:

    标签: javascript sendbird


    【解决方案1】:

    您收到该错误响应的原因是因为在代码时连接尚未完成

    sb.GroupChannel.createChannelWithUserIds()
    

    正在运行。

    您需要在 sb.connect() 的回调函数中添加该代码块,如下所示:

    function chatInit(){
        var sb = new SendBird({
            appId: 'my app id'
         });
    
         var userIds = ['another user'];
    
         sb.connect('test user','access token of user', function(user, error) {
             console.log(error);
    
             if(user){
                  var name ="name of channel";
                  sb.GroupChannel.createChannelWithUserIds(userIds, true, name ,'', '', function(channel, error) {
                      if (error) {
                           console.error(error);
                           return;
                      }
                  }); 
             }
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      • 2020-01-29
      • 2021-01-03
      • 2014-02-03
      • 1970-01-01
      • 2022-01-12
      相关资源
      最近更新 更多