异常:无效参数-API天气当前数据拉取

异常:无效参数-API天气当前数据拉取,api,exception,arguments,Api,Exception,Arguments,我和一个老人正在努力学习一种新的技巧。第一个职位。请仁慈一点。我一直收到这个消息。我试着用控制台记录它(第13行)得到同样的信息 我只想从openweather网站上获取电子表格A2中指定城市的高低数据 日志没有显示我的API密钥或A2位置的位置。我看了两个小时,我的眼睛都在交叉。就像我说的,我是新来的。我肯定是我做错了什么。提前谢谢 Message Exception: Invalid argument: http://api.openweathermap.org/data/2.5/weath

我和一个老人正在努力学习一种新的技巧。第一个职位。请仁慈一点。我一直收到这个消息。我试着用控制台记录它(第13行)得到同样的信息

我只想从openweather网站上获取电子表格A2中指定城市的高低数据

日志没有显示我的API密钥或A2位置的位置。我看了两个小时,我的眼睛都在交叉。就像我说的,我是新来的。我肯定是我做错了什么。提前谢谢

Message Exception: Invalid argument: http://api.openweathermap.org/data/2.5/weather?q={location}&appid=${key} (line 14, file "Code")

出现此问题是因为获取了无效的url。 注意到url中出现语法${},您试图使用普通字符串中的模板文本定义url。 要定义模板文字字符串,应使用反勾号(`)而不是引号(')

有关模板文字的更多信息,请参见:

问题可能在第12行。使用反勾号(`)将允许您使用${variable}语法(模板文本)格式化字符串。引号字符(')不会这样做,而是保留键入的字符串。Demvamko AndrijaKovac你是凡人中的神。非常感谢。它起作用了。
function getCurrentData() { 
    //API key
    const key = "API key Here(actually a number)"
    const ss = SpreadsheetApp.getActiveSpreadsheet() 
    const wsLocation = ss.getSheetByName("Location") 
    const wsLiveData = ss.getSheetByName("Live Data") 
    const location = wsLocation.getRange("A2").getValue()
    const highCell = wsLiveData.getRange("B4")
    const lowCell = wsLiveData.getRange("C4") 
    
    let apiURL = 'https://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${key}'
    //console.log(apiURL)
    const resText =    UrlFetchApp.fetch(apiURL).getContentText()
    console.log(resText)
}