Google apps script 将cUrl源代码转换为Google应用程序脚本

Google apps script 将cUrl源代码转换为Google应用程序脚本,google-apps-script,Google Apps Script,我尝试将cUrl源代码转换为Google应用程序脚本 我在卷发上成功了 但无法转换谷歌应用程序脚本源 我认为Google应用程序脚本源代码中存在一些问题,但我无法解决它 多谢各位 旋度源 谷歌应用程序脚本 哦。解决了 我可以快乐地回答自己 function test3(){ var message = "Hello World!"; var discordUrl = "https://api.channel.io/open/v3/user-chats/5f7264

我尝试将cUrl源代码转换为Google应用程序脚本

我在卷发上成功了

但无法转换谷歌应用程序脚本源

我认为Google应用程序脚本源代码中存在一些问题,但我无法解决它

多谢各位

  • 旋度源
  • 谷歌应用程序脚本

  • 哦。解决了

    我可以快乐地回答自己

    function test3(){
    var message = "Hello World!";
    var discordUrl = "https://api.channel.io/open/v3/user-chats/5f7264/messages?botName=%EA%B0%9C%EB%B0%9C%ED%97%A4%EC%95%84%EB%A6%BC";
    var payload1 = {
          "chatKey": "userChat-5f72645",
          "id": "5f72932",
          "channelId": "386",
          "chatType": "userChat",
          "chatId": "5f726434ea42",
          "personType": "manager",
          "personId": "683",
          "requestId": "4dcb55b1c",
          "createdAt": 160199,
          "version": 1,
          "blocks": [
            {
              "type": "text",
              "value": message,
            }
          ],
        "plainText": message,
      }
          
       
    var params = {
      'method': 'post',  
      'contentType': 'application/json',
      'headers': {
            'x-access-key': '5f4bbf',
            'x-access-secret': '342b0698327',
      },
      'payload': JSON.stringify(payload1)
      }
    
      var response = UrlFetchApp.fetch(discordUrl, params);
      
      var text=response.getContentText();
      Browser.msgBox('테스트', text, Browser.Buttons.YES_NO_CANCEL);
      
      Logger.log(response.getContentText());
    }
    
    
    成功了


    谢谢大家!

    你的错误是什么?没有错误,但不起作用。那个代码是在channeltalk中发送消息,但我没有任何消息。旋度源运行良好。日志显示了什么?其中,
    有效载荷
    ?作为副本关闭。如果经过适当研究后,所有链接答案中的修改对您不起作用,请提出一个新问题。@TheMaster谢谢。但当我使用“有效载荷”时,出现了异常:请求失败,返回代码415错误。您得到的错误是什么?没有错误,但不工作。那个代码是在channeltalk中发送消息,但我没有任何消息。旋度源运行良好。日志显示了什么?其中,
    有效载荷
    ?作为副本关闭。如果经过适当研究后,所有链接答案中的修改对您不起作用,请提出一个新问题。@TheMaster谢谢。但当我使用“有效负载”时,出现了类似异常的错误:请求失败,返回代码415错误。
    
        function test3() {
    
     
    
      var discordUrl = "https://api.channel.io/open/v3/user-chats/5f72xxxxxxxx/messages?botName=helloworldbot";
    
     
    
      var params = {
    
        'method': 'POST',
    
        headers: {
    
     
    
          'accept': 'application/json',
    
          'ContentType': 'application/json',
    
          'x-access-key': '5f72651xxxxxxxxxx',
    
          'x-access-secret': '342b0f6dfxxxxxxxxxx',
    
        },
    
     
    
        "chatKey": "userChat-5f72xxxxxxxxxx",
    
        "id": "5f729323xxxxxxxxxx",
    
        "channelId": "33086",
    
        "chatType": "userChat",
    
        "chatId": "5f72645xxxxxxxxxx",
    
        "personType": "manager",
    
        "personId": "68813",
    
        "requestId": "4dxxxxxxxxxx",
    
        "createdAt": 1601xxxxxxxxxx,
    
        "version": 1,
    
        "blocks": [{
    
          "type": "text",
    
          "value": "Hello World"
    
        }],
    
        "plainText": "Hello World"
    
      };
    
      var response = UrlFetchApp.fetch(discordUrl, params);
    
     
    
      var text = response.getContentText();
    
      Browser.msgBox('test', text, Browser.Buttons.YES_NO_CANCEL);
    
     
    
      Logger.log(response.getContentText());
    
    }
    
    function test3(){
    var message = "Hello World!";
    var discordUrl = "https://api.channel.io/open/v3/user-chats/5f7264/messages?botName=%EA%B0%9C%EB%B0%9C%ED%97%A4%EC%95%84%EB%A6%BC";
    var payload1 = {
          "chatKey": "userChat-5f72645",
          "id": "5f72932",
          "channelId": "386",
          "chatType": "userChat",
          "chatId": "5f726434ea42",
          "personType": "manager",
          "personId": "683",
          "requestId": "4dcb55b1c",
          "createdAt": 160199,
          "version": 1,
          "blocks": [
            {
              "type": "text",
              "value": message,
            }
          ],
        "plainText": message,
      }
          
       
    var params = {
      'method': 'post',  
      'contentType': 'application/json',
      'headers': {
            'x-access-key': '5f4bbf',
            'x-access-secret': '342b0698327',
      },
      'payload': JSON.stringify(payload1)
      }
    
      var response = UrlFetchApp.fetch(discordUrl, params);
      
      var text=response.getContentText();
      Browser.msgBox('테스트', text, Browser.Buttons.YES_NO_CANCEL);
      
      Logger.log(response.getContentText());
    }