使用Google Apps Script开发Telegram Bot时API返回荷兰语错误,如何改为英语?
解决Telegram Bots API返回非英语错误信息的问题
问题场景
使用Google Apps Script(GAS)通过Webhook开发Telegram Bot时,GAS和Telegram均设置为英语环境,但调用API时返回荷兰语的异常提示:
Exception: Verzoek voor https://api.telegram.org is mislukt. Foutcode: 404. Ingekorte serverreactie: {"ok":false,"error_code":404,"description":"Not Found"} (Gebruik de optie muteHttpExceptions om de volledige reactie te onderzoeken.)
at sendMessage(Code:167:15)
at start(Code:91:3)
at doPost(Code:32:7)
解决步骤
- 调整Google Apps Script的区域设置:这是解决GAS系统异常提示为荷兰语的核心操作。在GAS编辑器右上角点击齿轮图标进入设置,找到「区域设置」选项,选择英语(如
English (United States)),保存后重新运行脚本,GAS的系统级异常提示会跟随区域设置切换为英语。 - 在API请求中强制指定语言参数:调用Telegram Bots API时,在请求里添加
language_code=en参数。比如调用sendMessage接口时,构造的URL示例:
若使用POST请求,也可在JSON请求体中加入该参数,确保API返回的错误描述强制使用英语。https://api.telegram.org/bot<你的BotToken>/sendMessage?chat_id=<聊天ID>&text=测试&language_code=en
内容的提问来源于stack exchange,提问作者Nathan Tew
相关产品推荐
相关产品推荐

