Youtube API未捕获(在承诺中)错误:请求失败,状态码为403
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Youtube API未捕获(在承诺中)错误:请求失败,状态码为403相关的知识,希望对你有一定的参考价值。
我正在尝试将YouTube API集成到新的Vuejs应用程序中,我正在浏览器中对其进行测试并继续收到404错误。
我确实丢失了www
,但是当我提出请求时,我仍然会遇到同样的错误。我的代码中有没有看到错误的东西?这是一个角色问题吗?如果是这样,在Vuejs解决这个问题的标准做法是什么?我在Reactjs中做了类似的应用程序,并没有遇到这个问题。
<template>
<div>
<SearchBar @termChange="onTermChange"></SearchBar>
</div>
</template>
<script>
import axios from "axios";
import SearchBar from "./components/SearchBar";
const API_KEY = "<api_key>";
export default {
name: "App",
components: {
SearchBar
},
methods: {
onTermChange(searchTerm) {
axios
.get("https://www.googleapis.com/youtube/v3/search", {
params: {
keys: API_KEY,
type: "video",
part: "snippet",
q: searchTerm
}
})
.then(response => console.log(response));
}
}
};
</script>
我在回复中注意到我收到了这条消息:
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
我不确定这意味着什么。
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
这意味着您已超出限制,可以从youtube投放视频。您需要创建一个帐户才能显示更多视频。
如果您确定没有超出限制/拥有一个帐户,请检查您的开发者控制台是否已打开API。 Developer Console。
我建议在你的电话中添加一个catch
来处理将来的错误。
axios
.get("https://www.googleapis.com/youtube/v3/search", {
params: {
keys: API_KEY,
type: "video",
part: "snippet",
q: searchTerm
}
})
.then(response => console.log(response));
.catch(err => { console.log(err); }
把你的Api密钥放在url中
“Qazxswpoi”
https://www.googleapis.com/youtube/v3/search?key=YOUR_API_KEY
你会找到一个例子axios.get("https://www.googleapis.com/youtube/v3/search?key=Your_Api_Key", {
params: {
type: "video",
part: "snippet",
q: searchTerm
}
})
.then(response => console.log(response));
以上是关于Youtube API未捕获(在承诺中)错误:请求失败,状态码为403的主要内容,如果未能解决你的问题,请参考以下文章
Axios GET请求在我的本地版本上运行,但在Heroku上失败-未捕获(承诺)错误:请求失败,状态码为500
React axios api调用错误:未捕获(在承诺中)TypeError:setTempFetch不是函数