【发布时间】:2020-04-19 07:55:17
【问题描述】:
我正在尝试使用 DTN 的天气小部件希望在背景图像之上创建一个小部件。但是,我至少无法让小部件显示出来。以下是我的代码:
<HTML>
<head>
<script src="https://content-services.dtn.com/ui-widgets/local-weather-widget/local-weather-widget-1.0-latest.js">
</script>
</head>
<body>
<p>This is a weather widget:</p>
<div class="widget" id="local-weather-widget" style="background: rgb(255, 255, 255); padding: 10px;">
</div>
<script>
window.dtn.localWeather.createLocalWeatherWidget({
"apiKey": "oViXqthDGFNVw3IvAsnKrFG1AcfPyA6b",
"container": "#local-weather-widget",
"units": "Imperial",
"defaultLocation": {
"postalCode": "68033"
},
"stations": [
{
"id": "KTPH",
"displayName": "Station 1"
},
{
"id": "KSNA",
"displayName": "Station 2"
}
],
"showStationsSelect": true,
"showPostalCodeInput": true,
"showForecast": true,
"showCurrentConditions": true,
"showWeatherDetails": true,
"callbacks": {
"onStationChange": "",
"onPostalCodeChange": "",
"onWeatherChange": ""
}
});
</script>
</body>
</HTML>
根据我从我需要 API Key 获得启动信息的网站,我正在使用他们在网站上提供的测试 API Key。
【问题讨论】:
-
您是否尝试过使用自己的 API 密钥,就像说明告诉您的那样?您是否从浏览器的开发者控制台中收集到任何有用的信息?
-
很遗憾,当我与他们联系以获取 API 密钥时,他们的电子邮件无法使用,我还有其他方法可以获得吗?
-
我在某些 API 密钥上收到 403,并显示以下消息:“密钥有效,但未获得域授权。请联系 DTN 客户支持。”
-
该消息告诉您您需要知道的一切。您正在尝试使用与您请求小部件的域无关的 API 密钥。想一想:如果您的 API 密钥与您的域 example.com 相关联,然后有人提取该 API 密钥并从 anotherdomain.com 开始使用它,您认为应该允许吗?还是您认为应该阻止从 anotherdomain.com 发出请求的人使用您的 API 密钥来执行此操作?在您的示例代码中,您正在劫持其他人的 API 密钥。所以是不允许的。
-
我找到了解决方案,我需要联系会员来授权我的域,他们也提供了 API 密钥。
标签: javascript html weather