我正在尝试使用 Youtube Data API v3 运行一些查询,它应该从 Youtube API 返回一些视频,但我收到“必需参数:部分”的错误
我已经尝试使用相同的键值对在 Postman 上发出相同的请求 (GET),它在 Postman 中工作得很好,但在我的 React 和 Axios 应用程序中却没有,它会抛出这个错误:
{error: {errors: [,…], code: 400, message: "Required parameter: part"}}
error: {errors: [,…], code: 400, message: "Required parameter: part"}
code: 400
errors: [,…]
0: {domain: "global", reason: "required", message: "Required parameter: part", locationType: "parameter",…}
domain: "global"
location: "part"
locationType: "parameter"
message: "Required parameter: part"
reason: "required"
message: "Required parameter: part"
import axios from 'axios';
const KEY = 'AIzaSyAL9jCDWvRD2G5nUgBrLEgEhZTQsRvzt80';
export default axios.create({
baseURL: 'https://www.googleapis.com/youtube/v3',
params: {
part: 'snippet',
maxResults: 5,
key: KEY
}
});
和我的应用程序组件:
import React from 'react';
import SearchBar from './SearchBar';
import youtube from '../components/apis/youtube';
class App extends React.Component {
onTermSubmit = (term) => {
youtube.get('/search', {
params: {
q: term
}
});
}
render() {
return (
<div className="ui container">
<SearchBar onFormSubmit={this.onTermSubmit} />
</div>
)
}
}
export default App;