【问题标题】:"Invalid API key. Please see https://openweathermap.org/faq#error401 for more info."\"无效的 API 密钥。请参阅 https://openweathermap.org/faq#error401 了解更多信息。\"
【发布时间】:2022-11-23 03:24:47
【问题描述】:

请尝试在我的 vue js web 应用程序中获取开放天气 api 这是错误,请问我该如何解决这个问题 这是错误: “无效的 API 密钥。请参阅 https://openweathermap.org/faq#error401 了解更多信息。”

这是我的 vue js 代码:

<template></template>

<script>
import { onMounted, ref } from "@vue/runtime-core";
export default {
  setup() {
    const weatherData = ref([]);
    const latitude = ref("");
    const longitude = ref("");
    onMounted(() => {
      if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition((position) => {
          latitude.value = position.coords.latitude;
          longitude.value = position.coords.longitude;
        });
      } else {
        alert("Your Browser Doesn't support Geolocation");
        console.log("Your Browser do not Support Geolocation");
      }

      fetch(
        `https://api.openweathermap.org/data/2.5/weather?lat={${latitude.value}}&lon={${longitude.value}}&appid={dace6a593d778f8773c2fd033a16a91a}`
      )
        .then((data) => data.json())
        .then((response) => {
          weatherData.value = response;
          console.log(response);
        })
        .catch((err) => console.log(err.message));
    });
  },
};
</script>

<style>
</style>

我期待结果 json格式请帮忙

【问题讨论】:

  • 嘿伙计,你的 api 密钥是字符串,所以尝试将它作为一个传递,appid=dace6a...(没有 {})

标签: vue.js


【解决方案1】:

存在语法错误。我们这个

https://api.openweathermap.org/data/2.5/weather?lat=${latitude.value}&amp;lon=${longitude.value}&amp;appid=dace6a593d778f8773c2fd033a16a91a

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 2018-07-20
    • 2017-12-21
    • 2020-10-13
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    相关资源
    最近更新 更多