Bor*_*lys 2 web-applications add-on google-apps-script http-status-code-302 telegram-bot
Execute as: Me, Who has access: Anyone。网络应用程序
function doPost(e) {
myLog('Received from Addon: ' + JSON.stringify(e));
// console.log('parameters from caller ' + JSON.stringify(e));
return ContentService.createTextOutput(JSON.stringify(e));
}
Run Code Online (Sandbox Code Playgroud)
Webhook aTelegram-bot 和此 Web 应用程序已设置。
添加在
function sendPost() {
var sheetURL = SpreadsheetApp.getActiveSpreadsheet().getUrl();
// var webAppUrl = "https://script.google.com/macros/s/#####/exec"; // 7: Part_1 - WebApp: My
var webAppUrl = "https://script.google.com/macros/s/###/exec"; // 7: Part_1 - WebApp: Tester
// var auth = ScriptApp.getOAuthToken();
// var header = { 'Authorization': 'Bearer ' + auth };
var payload = { scriptName: 'updateData', sheetURL: 'sheetURL' };
var options = {
method: 'post',
// headers: header,
muteHttpExceptions: true,
payload: payload
};
var resp = UrlFetchApp.fetch(webAppUrl, options);
var respCode = resp.getResponseCode();
console.log('resp: ' + respCode);
myLog(respCode);
var respTxt = resp.getContentText();
myLog('Response from webApp: ' + respTxt);
console.log('resp: ' + respTxt);
}
Run Code Online (Sandbox Code Playgroud)
这是该过程的简短视频(EN 字幕)。
还https://api.telegram.org/bot{API_token}/getWebhookInfo表明没有错误:
{"ok":true,"result": {"url":"https://script.google.com/macros/s/###/exec", "has_custom_certificate":false, "pending_update_count":0, "max_connections":40,"ip_address":"142.250.***.***"}}
Run Code Online (Sandbox Code Playgroud)
无论如何,它都会干扰插件的测试。
{"ok":true,"result": {"url":"https://script.google.com/macros/s/###/exec", "has_custom_certificate":false, "pending_update_count":1, "last_error_date":1635501472, "last_error_message":"Wrong response from the webhook: 302 Moved Temporarily", "max_connections":40,"ip_address":"142.250.1***.***"}}
问题:是否有人遇到过这种情况,并会建议一种解决方法,说明如何在这种情况下将脚本作为插件进行测试?
http-status-code-302指的是重定向。如果ContentService使用,Google 会暂时将资源重定向到另一个域来提供内容。使用时不会执行此重定向HtmlService。因此,如果问题与重定向有关,请改用HtmlService。
| 归档时间: |
|
| 查看次数: |
1797 次 |
| 最近记录: |