是否可以从 Google 文档内部发送 HTTP 请求? [英] Is it possible to send HTTP request from inside Google docs?
问题描述
我想从 Google Drive 电子表格向某个 REST 服务发送 HTTP 请求.
I want to send an HTTP request to some REST service from Google drive spreadsheet.
这可能吗?
推荐答案
使用 Google Apps Script,您可以向 外部 API 来自 Google Docs/Sheets/etc.使用 UrlFetchApp 类:
Using Google Apps Script, you can make HTTP requests to external APIs from inside Google Docs/Sheets/etc. using the UrlFetchApp class:
var url = 'https://gdata.youtube.com/feeds/api/videos?'
+ 'q=skateboarding+dog'
+ '&start-index=21'
+ '&max-results=10'
+ '&v=2';
var response = UrlFetchApp.fetch(url);
Logger.log(response);
注意:
此服务需要 https://www.googleapis.com/auth/script.external_request 范围.在大多数情况下,Apps 脚本会自动检测并包含脚本所需的范围,但如果您明确设置范围,则必须手动添加此范围才能使用 UrlFetchApp.
This service requires the https://www.googleapis.com/auth/script.external_request scope. In most cases Apps Script automatically detects and includes the scopes a script needs, but if you are setting your scopes explicitly you must manually add this scope to use UrlFetchApp.
参考:https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
这篇关于是否可以从 Google 文档内部发送 HTTP 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!