簡體   English   中英

如何擺脫這個 - 消息:{'你沒有訂閱這個 API.'}。?

[英]How to get rid of this - message:{'You are not subscribed to this 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;

如果您在 RapidAPI 上的所有設置都正確,我建議您在不使用變量的情況下傳遞密鑰,因為您可能傳遞的是未定義的。 對於 undefined,我們得到完全相同的錯誤。

您必須 select 定價計划,即使它是免費計划。 Go 頁面上的“定價”為 API 和 select 一個計划。 這為我解決了這個問題。

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

如果您未訂閱 api,請確保您在快速 api 集線器上實際訂閱 api如果您未訂閱 api,您將收到一條錯誤消息,通知您的呼叫不會成功

消息:您尚未訂閱此 api rapidapi

視頻示例

也許問題出在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));
  }

對於遇到此問題的其他任何人:我所做的監督是在 RapidAPI 密鑰中添加“Bearer”。 它應該只是鑰匙,前面沒有任何東西。

確保您的 select 計划是免費計划還是高級計划。

https://rapidapi.com/tipsters/api/hotels-com-provider/pricing

這可能是陳舊的,但對其他人有幫助:

您要做的第一件事是避免將其放在.env中。 在將其放入.env之前,確保它在代碼片段(不安全的方法)中正常工作(當前最佳實踐)。

例如,您應該首先這樣做:

const options = {
     'X-RapidAPI-Key': 'theVeryLenthyKey',
    'X-RapidAPI-Host': 'theAPI.p.rapidapi.com'
  }
};

而不是這個:

const options = {
    'X-RapidAPI-Key': process.env.THE_VARIABLE_NAME_YOU_USED,
        'X-RapidAPI-Host': 'theAPI.p.rapidapi.com'
      }
    };

如果您訂閱了免費計划但仍然收到此錯誤“消息:{'您沒有訂閱此 API.'}”

該問題可能與 .env 位置有關。 嘗試將其放在文件夾的根目錄中,而不是 src 文件夾中。

如果您三次單擊 API 密鑰從代碼片段到 select 它,它實際上不會 select 整個密鑰。 我就是這樣解決我的。在這里檢查

我已經通過簡單的直接傳遞密鑰解決了這個問題,就像這樣

..................................................... .................. 導出 const exerciseOptions = { 方法:“GET”,標題:{“X-RapidAPI-Host”:“exercisedb.p. rapidapi.com", "X-RapidAPI-Key": "b8c1892349msha8fe6c74d4c0831p14073ajsnd6696eb595e6", }, };

..................................................... ...................... 不要通過 .env 文件傳遞密鑰

我得到了同樣的回復說{消息:你沒有訂閱......但我是,我確定。 所以問題是它無法從 .env 文件中讀取。 所以我在開發階段使用了直接將密鑰放入代碼中的手動方法,但是當我部署項目時,我將其添加到托管服務的環境變量中,它工作得很好。

如果您將密鑰作為變量傳遞,請確保將您的 .env 文件放在根文件夾中(環境變量)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM