【发布时间】:2019-01-31 06:00:44
【问题描述】:
我有一个尝试从频道中获取一些视频以使用 axios 做出反应并获取对 api 的请求的示例。一切看起来都不错,但是当它编译时,我收到一个控制台错误,指出:GET https://api.vimeo.com/channels/180097/videos/&key=*********** 401 (Authorization Required
访问令牌是我注册时生成的正确令牌。这是设置的代码:
import React, { Component } from 'react';
import axios from 'axios';
const API_KEY = '***********************';
class Apicall extends Component {
componentDidMount() {
this.getChannel();
}
getChannel() {
axios.get(`https://api.vimeo.com/channels/180097/videos/&key=${API_KEY}`)
.then(res => {
const videos = res.data.data.children.map(obj => obj.data);
this.setState({videos});
});
}
constructor(props) {
super(props);
this.state = {
channel_id: '180097',
data: [],
videos: [],
per_page: '5',
paging: {
first: '/channels/180097/videos?page=1',
last: '/channels/180097/videos?page=3'
}
}
this.getChannel = this.getChannel.bind(this);
}
render(){
return (
<div className="container">
<h1></h1>
<ul>
{this.state.videos.map(video =>
<li key={video.uri}></li>
)}
</ul>
</div>
);
}
}
export default Apicall;
为什么仍然没有获得访问令牌?
【问题讨论】:
-
我可能错了,但我认为 url 有一个额外的 slash.axios.get(
https://api.vimeo.com/channels/180097/videos/&key=${API_KEY}) -- 应该是 axios.get(https://api.vimeo.com/channels/180097/videos&key=${API_KEY}) 对吧? -
您不应该在标头而不是 URL 中发送访问令牌吗? developer.vimeo.com/api/authentication#best-practices
-
@MartinBroadhurst 我只是按照命令行中的文档所述进行操作,它给了我:Invoke-WebRequest:无法绑定参数“标头”。无法将“System.String”类型的“Authorization: Bearer *****************”值转换为“System.Collections.IDictionary”类型。
-
@KirkLarkin 我只是按照命令行中的文档所述进行操作,它给了我:Invoke-WebRequest:无法绑定参数“标头”。无法将“System.String”类型的“授权:Bearer *****************”值转换为“System.Collections.IDictionary”类型。我不知道为什么
标签: javascript reactjs api get axios