如何摆脱这种情况-消息:{'您尚未订阅此API。'}。?

时间:2020-04-26 18:23:04

标签: reactjs api

import React from 'react';
import './App.css';

function App() {
    fetch("https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/quickAnswer?q=How%20much%20vitamin%20c%20is%20in%202%20apples%253F", {
            "method": "GET",
            "headers": {
                "x-rapidapi-host": "[host]",
                "x-rapidapi-key": "[key]"
            }
        })
        .then(response => {
            console.log(response);
        })
        .catch(err => {
            console.log(err);
        });
    return ( <
        div className = "App" >
        <
        form className = 'searchform' >
        <
        input className = 'search-bar'
        type = "text" / >
        <
        button className = 'search-bar'
        type = 'text' > Submit < /button> < /
        form > <
        /div >
    );
}

export default App;

3 个答案:

答案 0 :(得分:2)

如果您在 RapidAPI 上的所有设置都正确,我建议您在不使用变量的情况下传递密钥,因为您可能传递的是未定义的。对于 undefined,我们得到完全相同的错误。

答案 1 :(得分:1)

<块引用>

您必须选择一个定价计划,即使它是免费计划。转到 API 页面上的“定价”,然后选择一个计划。这为我解决了这个问题。

https://api.rakuten.net/Top-Rated/api/e-mail-check-invalid-or-disposable-domain/discussions/9487/keep-getting-this-response-%22You-are-not-subscribed-to-this-API.%22

答案 2 :(得分:0)

也许问题出在GET上,尝试一下。让我知道,是否可行。

state = {
    url:
      "<url>",
    header: {
      "x-rapidapi-host": "<host>",
      "x-rapidapi-key": "<key>"
    }
  };

  componentDidMount() {
    axios
      .post(this.state.url, this.state.header)
      .then(res => {
        console.log(res.data);
      })
      .catch(err => console.log("err" + err));
  }