前提・実現したいこと
タイトルの通り、React + Electron で作成しているアプリの内部で TwitterAPI を使用したいと思っています。
ちなみに、Thunder Client にて以下の URL と Header を指定した場合の動作確認は取れているので、React特有、あるいはElectron特有のエラーが出ているのではないか、と考えています。
補足情報等が必要であれば随時追記していきますので、何卒宜しくお願い致します。
発生している問題・エラーメッセージ
xhr.js:187 Refused to connect to 'https://api.twitter.com/2/tweets/search/recent?query=python' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback. dispatchXhrRequest @ xhr.js:187 Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:99)
該当のソースコード
typescript
1import axios from "axios"; 2import React, { useEffect } from "react"; 3 4export const App = () => { 5 useEffect(() => { 6 const http = async () => { 7 const config = { 8 headers: { 9 Authorization: 10 "Bearer <BEARER_TOKEN>", 11 }, 12 }; 13 axios 14 .get( 15 "https://api.twitter.com/2/tweets/search/recent?query=python", 16 config 17 ) 18 .then((res) => console.log(res)) 19 .catch((e) => console.log(e)); 20 }; 21 http(); 22 }, []); 23 24 return <div></div>; 25};
追加情報
どうやら TwitterAPI に限らず、JSON placeholder のエンドポイントを叩きに行っても同様のエラーが出るようです。
Electronが問題っぽいですね、、



回答1件
あなたの回答
tips
プレビュー