是否可以从Google文档内部发送HTTP请求? [英] Is it possible to send HTTP request from inside Google docs?

查看:93
本文介绍了是否可以从Google文档内部发送HTTP请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Google云端硬盘电子表格向某些REST服务发送HTTP请求.

I want to send an HTTP request to some REST service from Google drive spreadsheet.

这可能吗?

推荐答案

使用Google Apps脚本,您可以向 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.

ref: https://developers.google. com/apps-script/reference/url-fetch/url-fetch-app

这篇关于是否可以从Google文档内部发送HTTP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆