Google 应用程序脚本 Youtube 服务无法插入实时聊天消息

Google app script Youtube service fails to insert live chat message

我在 google 应用程序脚本中使用 Youtube 服务编写了一个函数,用于在 youtube 实时聊天中插入消息。但是函数抛出错误

GoogleJsonResponseException: API call to youtube.liveChatMessages.insert failed with error: Request contains an invalid argument. at InsertLiveChatMessage (Code:122:41) at __GS_INTERNAL_top_f...

这是我在编辑器运行中尝试过的功能

function InsertLiveChatMessage(live_chat_id="Cg0KC0N5XzYtX1hVVy1jKicKGFVDdDR0LWplWTg1SmVnTWxaLUU1VVd0QRILQ3lfNi1fWFVXLWM", message="message")
{
  let response = {};
  let resource = {
    "snippet": {
      "liveChatId": live_chat_id,
      "type": "textMessageEvent",
      "textMessageDetails": {
        "messageText": message
      }
    }
  };

  try
  {
    response = YouTube.LiveChatMessages.insert(resource, "snippet");
  }
  catch(e)
  {
    response["error"] = "Something went wrong";
  }

  console.log(response);
}

我在 运行 上述功能之前启用了 Youtube 数据 api 服务并授予了权限。我从 Google API 资源管理器中借用了资源对象。有人可以指出它是 google 应用程序脚本问题还是与我的代码有关。

我认为如果处于类似状态,它会帮助某人调试此问题。

脚本代码本身没有问题。但是 google 不允许通过 api 发送聊天消息,除非您看到通过 YouTube website/app 发送消息的选项。我在这种情况下使用的帐户主要用于观看视频,但我从未使用该 Google 帐户流式传输过一次直播或参与过任何人的聊天。所以这更像是一个权限问题。