加入频道失败 DYNAMIC_USE_STATIC_KEY

join channel failed DYNAMIC_USE_STATIC_KEY

我正在尝试使用 Agora.io 实时视频系统。但是我在开发人员控制台中收到以下错误。

点击加入按钮后出现以下错误。

Agora-SDK [ERROR]: [713FF] Get server node failed [DYNAMIC_USE_STATIC_KEY] https://webrtc2-ap-web-1.agora.io/api/v1 DYNAMIC_USE_STATIC_KEY agora.js:161:41
Agora-SDK [INFO]: [713FF] Join failed: DYNAMIC_USE_STATIC_KEY agora.js:155:41
[ERROR] : join channel failed DYNAMIC_USE_STATIC_KEY live:1146:15

我得在agora管理面板上安排一下。我做错了什么。

 var rand = <?php echo rand(1111111,9999999); ?>;
 var agoraAppId = 'API ID HERE'; // set app id
 var channelName = "stream_<?php echo $creatorUserID;?>_"+rand; // set channel name
// join a channel
function joinChannel() {
  var token = generateToken();
  var userID = 0; // set to null to auto generate uid on successfull connection

  // set the role
  client.setClientRole('host', function() {
    console.log('Client role set as host.');
  }, function(e) {
    console.log('setClientRole failed', e);
  });

  // client.join(token, 'allThingsRTCLiveStream', 0, function(uid) {
  client.join(token, channelName, userID, function(uid) {
      createCameraStream(uid, {});
      localStreams.uid = uid; // keep track of the stream uid  
      console.log('User ' + uid + ' joined channel successfully');
      $('#main_live_video').html('')
      $('#publishBtn').removeAttr('disabled');
      $('#publishBtn').text("Please Wait");
      $('#publishBtn').addClass('hidden');
      $('.end_vdo_call').removeClass('hidden');

      $.post(requestUrl + "?f=live", {stream_name: channelName}, function(data, textStatus, xhr) {
                    if (data.status == 200) {
                      $('#live_post_id').val(data.post_id);
                    }
                  });
  }, function(err) {
      console.log('[ERROR] : join channel failed', err);
  });
}
function generateToken() {
 return null; // TODO: add a token generation
}

您收到的错误是因为您尝试使用启用了令牌认证的AppID,但在加入频道时没有传递令牌。

要解决这个问题,您通常有以下三种选择:

  1. 新建一个项目,生成一个新的AppID。打开Project Management tab within the Agora Console. Click the "Create" button in the upper left section of the screen. Within the dialog box, make sure to select the bottom option.

  2. 使用 Project Management tab within the Agora Console 在您的项目上生成一个临时令牌(有效期为 24 小时)。按照以下步骤操作:

    • Select 生成临时令牌选项
    • 输入频道名称并生成令牌
    • 使用您的令牌字符串更新 generateToken 函数,而不是 return 空值。
function generateToken() {
  return null; // add a token string here
}
  1. 实施令牌服务器并生成动态令牌。更多详情请查看:
function generateToken() {
  return null; // add a token string here
}

第二个选项不适用于您的实施,因为您要使用用户名生成频道名称并附加一个随机值。生成临时令牌时,您需要知道频道的名称。