google-apps-script - 使用 Google Apps 脚本和 Pastebin.com API 发布粘贴
问题描述
我正在尝试使用电子表格脚本编辑器中的Google Apps 脚本制作 Pastebin.com 粘贴。谁能告诉我我做错了什么?
function postPastebinPost() {
var options, url, apiKey, payload, response;
apiKey = <api key goes here>;
payload = 'Hello World';
options = {
'method' : 'post',
'payload' : payload
};
url = 'https://pastebin.com/api/api_post.php'
+ '?api_dev_key=' + apiKey
+ '&api_option=paste'
+ '&api_paste_code=' + encodeURIComponent(payload);
response = UrlFetchApp.fetch(url, options);
Logger.log(response);
}
我运行它,我的日志显示Bad API request, invalid api_option
. 我已经搜索了解决方案,但我没有找到任何解决方案。
文档:
• Google Apps 脚本的UrlFetchApp 类
解决方案
参数应在 POST 请求的有效负载中传递。
function postPastebinPost() {
var apiKey = 'YOUR KEY GOES HERE';
var text = 'Hello World';
var payload = {
api_dev_key: apiKey,
api_option: 'paste',
api_paste_code: text
};
var options = {
method : 'POST',
payload: payload
};
var url = 'https://pastebin.com/api/api_post.php';
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
推荐阅读
- excel - 在 MS Access VBA 中选择 Excel 范围抛出 1004 错误
- r - R 代码:如何使用自己的数据集更正 psych 包中的“解析错误(文本 = x,keep.source = FALSE)”输出
- javascript - 采用 XLSX JSON 格式并将其转换为动态 HTML 表格
- javascript - 为什么 JS 数组不包含 peek() 函数?
- android - 在用作位图的 webp 图像中进行更改(谷歌地图)
- javascript - 谁能帮我理解 Leetcode 自除数练习的解决方案
- ruby-on-rails - 如何在 Rails/Rspec 的开发和生产中检索主机 url?
- arduino - arudino car bot的问题,伺服电机随机移动也很快变热
- vba - 单击按钮时如何在 VBA 中编码以请求密码?
- php - 获取自定义帖子类型的 id 和标题以使用 FCM 发送通知