
试图制作一个谷歌表格来将雅虎新闻的日文 RSS 提要翻译成英文。创建了一个有时可以工作的函数,但有时会停止工作并返回错误。(错误代码未定义,但显示 Invalid Arg)。
最初,当我在谷歌表格中调用它时,它工作正常。但是当我添加更多行时,最终会作为错误返回。
任何想法都将受到高度欢迎。
出现错误的 Google 表格的屏幕截图:

/**
*Translates to Japanese to English with DeepL
*
* @param arg 1 The original text in Japanese
* @customFunction
*/
function JPYTRANS(arg1) {
//API Key for Deepl
const key = "c7a80658-9945-8b08-15ca-a8ce3d7281ac:fx"
var myLang = "EN-US"
let apiURL = `https://api-free.deepl.com/v2/translate?auth_key=${key}&target_lang=${myLang}&text=${arg1}`
var resText = UrlFetchApp.fetch(apiURL).getContentText()
var resJSON = JSON.parse(resText)
//Pulls just the part of the JSON object we want. Took me forever to get this right!!!
return resJSON.translations && resJSON.translations.length > 0 ? resJSON.translations[0].text : "No value"
}