这是我第一次使用Marvel API,但由于某种原因,它只是在控制台中向我发送了一个错误状态401(未授权)。我已经包含了API密钥。但是仍然会得到错误
import React,{Component} from 'react'
import axios from 'axios';
class Home extends Component {
componentDidMount(){
let api = 'APIHERE'
axios.get(`https://gateway.marvel.com/v1/public/comics?apikey=${api}`)
.then(res=>{
console.log(res)
}).catch(error =>{
console.log(error)
})
}
render(){
return(
<div className = "container">
<h4>Characters</h4>
</div>
)
}
}
export default Home;
发布于 2019-03-19 17:28:47
您需要添加时间戳和散列键以及apiKey,才能成功调用API。
发布于 2020-10-10 01:10:07
首先,您必须按照api文档中指定的方式安装md5 .Second,您必须发送3个参数才能通过身份验证。
ts :时间戳
apikey :公钥
哈希: md5(ts+publickey+privatekey)
如果您使用的是react-native :请尝试使用hex_md5==>https://www.npmjs.com/package/react-native-md5
或者尝试安装md5库。
https://stackoverflow.com/questions/53136339
复制相似问题