質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

1回答

2676閲覧

Reactでこんなエラーが出ました!

Kosuke0906

総合スコア13

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2019/12/01 11:17

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

EDAMAMを使ってAPIを取得してReactに組み込んだらこんなエラーが出てしまいました。

そうですか。で、どうしたいのでしょうか?


https://developer.edamam.com/faq

Do you support direct requests from the browser (AJAX, JSONP, CORS)?

  • For the Recipe Analysis API and Nutrition Data API the answer is no and we currently don't plan to. There are two reasons behind this:

First, to access one of these APIs the request needs to include valid credentials (for example app_id and app_key). This would make it very easy for somebody to steal them.

The second reason is, that direct access means direct charges from Edamam caused by the use of your site.

Instead we expect that our customers develop server-side solutions that save the responses.

For the Diet Recommendations API and Recipe Search API we do support JSONP through the callback parameter. However, we are discouraging this, because of the same security issue.

投稿2019/12/01 11:54

thyda.eiqau

総合スコア2982

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問