Javascript Can';t从401的Marvel API状态获取数据

Javascript Can';t从401的Marvel API状态获取数据,javascript,reactjs,api,axios,Javascript,Reactjs,Api,Axios,这是我第一次使用MarvelAPI,但出于某种原因,它只是在控制台中向我发送了一个错误状态401(未经授权)。我已经包含了API密钥。但还是会出错 import React,{Component} from 'react' import axios from 'axios'; class Home extends Component { componentDidMount(){ let api = 'APIHERE' axios.get(`http

这是我第一次使用MarvelAPI,但出于某种原因,它只是在控制台中向我发送了一个错误状态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;
import React,{Component}来自“React”
从“axios”导入axios;
类Home扩展组件{
componentDidMount(){
让api='apichere'
axios.get(`https://gateway.marvel.com/v1/public/comics?apikey=${api}`)
。然后(res=>{
console.log(res)
}).catch(错误=>{
console.log(错误)
})
}
render(){
返回(
人物
)
}
}
导出默认主页;

您需要在API调用成功的同时添加时间戳和哈希键。

首先您必须安装md5。其次,按照API文档中的规定,您必须发送3个参数才能获得身份验证

ts:时间戳

apikey:公钥

哈希:md5(ts+publickey+privatekey)

如果您使用的是react native:请尝试使用hex_md5==>https://www.npmjs.com/package/react-native-md5


或者尝试安装md5库。

如果您使用了错误的api密钥,请使用该端点的公钥