简体   繁体   English

无法从 401 的 Marvel API 状态获取数据

[英]Can't fetch data from Marvel API status of 401

It's my first time using the Marvel API, but for some reason It's just send me an error status of 401(Unauthorized) in the console.这是我第一次使用 Marvel API,但出于某种原因,它只是在控制台中向我发送了 401(未授权)的错误状态。 I already included the API key.我已经包含了 API 密钥。 but still gets the error但仍然得到错误

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;

您需要添加时间戳和哈希键以及 apiKey,以便 API 调用成功。

First you have to install md5 .Second as specified in the api documentation you have to send 3 parameter in order to get authenticated .首先,您必须按照 api 文档中的说明安装 md5 .Second 您必须发送 3 个参数才能进行身份验证。

ts : timestamp ts : 时间戳

apikey : public key apikey : 公钥

hash : md5(ts+publickey+privatekey)哈希:md5(ts+publickey+privatekey)

if you are using react-native : try with hex_md5==>https://www.npmjs.com/package/react-native-md5如果您使用的是 react-native :尝试使用 hex_md5==>https://www.npmjs.com/package/react-native-md5

or try to install md5 library instead .或者尝试安装 md5 库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM