首页 > 解决方案 > 从外部域获取 Google 表格中的活动用户名

问题描述

我有一个已发布的网络应用程序:

function doGet(request) {
   // DocumentApp.getActiveDocument();
    SpreadsheetApp.getActive();
  var about = Drive.About.get();
  var user = about.name;
  // Logger.log(Session.getActiveUser().getEmail());
   return ContentService.createTextOutput(user);
}

...在这个网址:

https://script.google.com/macros/s/AKfycbzTlhKJXrTAEPEba0l1KWqqzlkul2ntC-0iHi7_POj0wk7j3R6K/exec

这会产生用户全名所需的结果(在批准对用户数据的授权后 - URL 的后续运行不会提示进行身份验证或批准)

就是我想从此 App Script 中检索的数据:

function Test3() {
  var options = {
    'method' : 'get', 
    'followRedirects' : true,
    // 'validateHttpsCertificates' : 'true',
    'muteHttpExceptions' : true,
    'contentType' : 'null'
  };

 var url = "https://script.google.com/macros/s/AKfycbzTlhKJXrTAEPEba0l1KWqqzlkul2ntC-0iHi7_POj0wk7j3R6K/exec"

  var response = UrlFetchApp.fetch(url, options);
  // var response = test2() ;
  // var myName = response.getContentText();
  Browser.msgBox("[" + response + "]");
  }

但我无法获得这些数据。相反,我得到一个页面 HTML 文本,它相当于一个 Google 登录页面。

同样,只需从浏览器手动运行 URL,因为任何用户都会生成用户名网页,那么为什么从应用脚本运行时,它不能只检索该页面的结果?

我错过了什么?当然,我离获取这些数据还有一些简单的语法。

标签: google-apps-scripturlfetch

解决方案


推荐阅读