質問編集履歴
2
fetch mode corsでyahoo apiからresponceデータを取得可能
title
CHANGED
File without changes
|
body
CHANGED
@@ -95,4 +95,57 @@
|
|
95
95
|
API自体をたたけていないようです。
|
96
96
|

|
97
97
|
|
98
|
-
どうしたらAPIのデータを取得できるのかご教示いただけたら幸いです。
|
98
|
+
どうしたらAPIのデータを取得できるのかご教示いただけたら幸いです。
|
99
|
+
|
100
|
+
10/18 追記
|
101
|
+
fetchのmodeをcors指定にして、クロームブラウザの拡張ライブラリ「Access-Control-Allow-Origin」をONして
|
102
|
+
yahoo APIにアクセスしたところ、responseでデータの取得はできました
|
103
|
+
ただし、strictモードでのエラーが発生しており画面にデータを表示できていない状態です。
|
104
|
+
|
105
|
+
yahoo api(V2)はjsonpには対応していないようですがcorsには対応していると思われます。
|
106
|
+
クロスサイトオリジンの制限はブラウザでの制限なのでjsonpが使えないため
|
107
|
+
chromeの拡張ライブラリで乗り越えました。
|
108
|
+
|
109
|
+
問題がcorsからstrictモードになったので別に質問させていただきます。
|
110
|
+
ご回答者様ありがとうございました。
|
111
|
+
|
112
|
+
|
113
|
+
コードの編集
|
114
|
+
// const responce = await fetchJsonp(`${API_URL}?${queryString}`);
|
115
|
+
const responce = await fetch(`${API_URL}?${queryString}` ,{mode:'cors'});
|
116
|
+
|
117
|
+
responseデータ
|
118
|
+

|
119
|
+

|
120
|
+
|
121
|
+
Strictでのエラー
|
122
|
+
TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
|
123
|
+
at Function.r (<anonymous>:1:83)
|
124
|
+
at Object._callee$ (http://localhost:3000/static/js/bundle.js:55313:22)
|
125
|
+
at tryCatch (http://localhost:3000/static/js/bundle.js:1218:40)
|
126
|
+
at Generator.invoke [as _invoke] (http://localhost:3000/static/js/bundle.js:1452:22)
|
127
|
+
at Generator.prototype.<computed> [as next] (http://localhost:3000/static/js/bundle.js:1270:21)
|
128
|
+
at step (http://localhost:3000/static/js/bundle.js:55244:191)
|
129
|
+
at http://localhost:3000/static/js/bundle.js:55244:437
|
130
|
+
at new Promise (<anonymous>)
|
131
|
+
at http://localhost:3000/static/js/bundle.js:55244:99
|
132
|
+
at http://localhost:3000/static/js/bundle.js:55345:19
|
133
|
+
at http://localhost:3000/static/js/bundle.js:46615:18
|
134
|
+
at http://localhost:3000/static/js/bundle.js:46593:7806
|
135
|
+
at Object.onUpdate (http://localhost:3000/static/js/bundle.js:55671:7)
|
136
|
+
at Ranking.componentWillUpdate (http://localhost:3000/static/js/bundle.js:55478:20)
|
137
|
+
at updateClassInstance (http://localhost:3000/static/js/bundle.js:23570:18)
|
138
|
+
at updateClassComponent (http://localhost:3000/static/js/bundle.js:27457:20)
|
139
|
+
at beginWork (http://localhost:3000/static/js/bundle.js:28970:16)
|
140
|
+
at beginWork$1 (http://localhost:3000/static/js/bundle.js:33529:14)
|
141
|
+
at performUnitOfWork (http://localhost:3000/static/js/bundle.js:32504:12)
|
142
|
+
at workLoopSync (http://localhost:3000/static/js/bundle.js:32480:22)
|
143
|
+
at performSyncWorkOnRoot (http://localhost:3000/static/js/bundle.js:32106:9)
|
144
|
+
at http://localhost:3000/static/js/bundle.js:21439:24
|
145
|
+
at unstable_runWithPriority (http://localhost:3000/static/js/bundle.js:48446:12)
|
146
|
+
at runWithPriority$1 (http://localhost:3000/static/js/bundle.js:21389:10)
|
147
|
+
at flushSyncCallbackQueueImpl (http://localhost:3000/static/js/bundle.js:21434:7)
|
148
|
+
at flushSyncCallbackQueue (http://localhost:3000/static/js/bundle.js:21422:3)
|
149
|
+
at discreteUpdates$1 (http://localhost:3000/static/js/bundle.js:32243:7)
|
150
|
+
at discreteUpdates (http://localhost:3000/static/js/bundle.js:11156:12)
|
151
|
+
at dispatchDiscreteEvent (http://localhost:3000/static/js/bundle.js:14518:3)
|
1
fetch-jsonpをfetchに変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -83,4 +83,16 @@
|
|
83
83
|
テスト環境URL
|
84
84
|
http://localhost:3000/
|
85
85
|
|
86
|
-
以上、ご査収の程よろしくお願い申し上げます。
|
86
|
+
以上、ご査収の程よろしくお願い申し上げます。
|
87
|
+
|
88
|
+
|
89
|
+
追記 fetch-jsonpをfetchに変更
|
90
|
+
// const responce = await fetchJsonp(`${API_URL}?${queryString}`);
|
91
|
+
const responce = await fetch(`${API_URL}?${queryString}`);
|
92
|
+
|
93
|
+
fetchに変えてみたところ、下記エラーが表示されました。
|
94
|
+
「Failed to load resource: net::ERR_FAILED」
|
95
|
+
API自体をたたけていないようです。
|
96
|
+

|
97
|
+
|
98
|
+
どうしたらAPIのデータを取得できるのかご教示いただけたら幸いです。
|