【问题标题】:Return information to Card返回信息到卡
【发布时间】:2020-10-21 09:33:19
【问题描述】:

我正在开发一个卡片插件,在这张卡片里面我试图调用一个谷歌管理员 SDK API。 (GET https://www.googleapis.com/admin/directory/v1/groups/groupKey) groupKey 的值可以是组的电子邮件地址、组别名或我使用的唯一组 ID: AdminDirectory.Groups.Get(groupId)

我可以通过文本输入插入一个 groupKey,因为测试它会记录到 console.log。 现在我的问题是,如何将值作为文本或其他内容返回卡?

function myFunction(e) {
    // Input from user.
    var textInput = e.formInput.text_input;
    const groups = myGroupsM.GroupsM();
    // Export log on input from user "This works fine to console log"
    console.log(groups.Groups.get(textInput));

    // I tried below as a test to display text on card. Gives a error!
    // Is it because it returns wrapped information? like this -> {infoyouget: []}
    // Or do you need to give a parameter that you want to display?
    var testText = CardService.newTextParagraph()
    .setText(groups.Groups.get(text));
    
    var card = CardService.newCardBuilder();
    var cardSection = CardService.newCardSection().setHeader('Test Header')
    .addWidget(testText);
    // Found a thread on stackoverflow but it was about a clickable image. They suggested to use
    // brackets in the return as below.
    return [card.addSection(cardSection).build()];
} ```

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:
    • AdminDirectory.Groups.get(groupId) 为您返回一个类型的对象 {kind=XXX, email=YYY, nonEditableAliases=[ZZZ]...}
    • 您可以将此响应的各个元素作为字符串访问,例如: AdminDirectory.Groups.get(groupId).email
    • 如果您想将整个响应作为字符串返回到您的卡片,您可以简单地将对象转换为字符串,例如与AdminDirectory.Groups.get(groupId).toString()

    【讨论】:

    • 感谢您的回复,这帮助了我。刚刚开始了作为初级开发人员和在 Google Apps 脚本中编码的新旅程。我觉得太难了。
    猜你喜欢
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 2023-03-06
    • 2023-03-19
    • 1970-01-01
    • 2020-09-11
    • 2019-12-09
    • 2019-07-21
    相关资源
    最近更新 更多