首页 > 解决方案 > 如何在 Apps 脚本中创建 POST 请求?

问题描述

我的目标是使用 Gmail API 的上传附件功能。上传的文件将在我的 Gmail 插件中处理。我在此链接中找到了以下 POST 请求。

发布https://www.googleapis.com/upload/gmail/v1/users/userId/messages/send?uploadType=media

到目前为止,这是我的尝试:

function testPOST() {
  Logger.log('Testing of POST in Apps script');
//  var url = ScriptApp.getService().getUrl();
  var url = "https://www.googleapis.com/upload/gmail/v1/users/userId/messages/send"
  Logger.log('URL:'+url);

  var options =
      {
        "method"  : "POST",
        "uploadType" : "media"
      };

  // Trying to fetch the file
  var result = UrlFetchApp.fetch(url, options);
  Logger.log('Response code: ' + result.getResponseCode());    

  // maybe I need to use some function in 'Gmail.Users.*'
  }

标签: postgoogle-apps-script

解决方案


推荐阅读