EDAMAMを使ってAPIを取得してReactに組み込んだらこんなエラーが出てしまいました。
下記APIのurl。
https://developer.edamam.com/edamam-docs-recipe-api
##出現したエラー
GET https://api.edamam.com/search?q=chicken&app_id=b5d7a030&app_key=0b804e43df69b380805f07011d12eb4c 401 (Unauthorized)
localhost/:1 Access to fetch at 'https://api.edamam.com/search?q=chicken&app_id=b5d7a030&app_key=0b804e43df69b380805f07011d12eb4c' from origin 'http://localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
App.js:16 Uncaught (in promise) TypeError: Failed to fetch
App
1import React, { useEffect, useState } from "react"; 2import "./App.css"; 3 4const App = () => { 5 const APP_ID = "b5d7a030"; 6 const APP_KEY = "0b804e43df69b380805f07011d12eb4c"; 7 useEffect(() => { 8 getRecipes(); 9 }, []); 10 const getRecipes = async () => { 11 const response = await fetch( 12 `https://api.edamam.com/search?q=chicken&app_id=${APP_ID}&app_key=${APP_KEY}` 13 ); 14 const data = await response.json(); 15 console.log(data); 16 }; 17 return ( 18 <div className="App"> 19 <form className="search-form"> 20 <input className="search-bar" type="text" /> 21 <button className="search-button" type="submit"> 22 Search 23 </button> 24 </form> 25 </div> 26 ); 27}; 28 29export default App; 30
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。