I'm trying to fetch tweets from the Twitter API but I'm receiving network error and blocked by CORS error. I'm not sure what should I write differently or if I'm even setting up the header correctly to receive the response.
This is the code I have so far:
const Tweets = () => {
const [tweets, setTweets] = useState([])
useEffect(() => {
const token = process.env.REACT_APP_TWITTER_BEARER_TOKEN;
async function fetchTweets() {
const res = await axios.get('https://api.twitter.com/2/tweets/search/recent?query=%23ux', {
headers: {
'Authorization': `bearer ${token}`
}
});
if(res) {
setTweets(res.data);
}
console.log(res.data);
return res;
}
fetchTweets();
}, [])
return (
<div>
</div>
);
}
export default Tweets;