xdevplatform / Twitter-API-v2-sample-code

Sample code for the Twitter API v2 endpoints
https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api
Apache License 2.0
2.71k stars 998 forks source link

Recent search not working in browser. I am constantly getting CORS error #32

Closed bhavesh2799 closed 3 years ago

bhavesh2799 commented 3 years ago

`getTweets(){

var myHeaders = new HttpHeaders(); myHeaders.append("Authorization", "Bearer "+this.token); // myHeaders.append("Cookie", "guest_id=v1%3A161908241149107957; personalization_id=\"v1_ejJZ4HGUOXH10orpNKx4xQ==\"");

var requestOptions = { method: 'GET',

headers: myHeaders,
redirect: 'follow'

};

fetch("https://api.twitter.com/1.1/search/tweets.json?q==ECONOMICTIMES&max_results=10&tweet.fields=author_id,created_at,entities,geo,in_reply_to_user_id,lang,possibly_sensitive,referenced_tweets,source", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error)); } `

andypiper commented 3 years ago

This is not related to the v2 API (you have /1.1/ in the URL) so the fields and expansions will not work. Also, Twitter’s API does not support CORS.

I recommend that you use https://twittercommunity.com for follow-up questions since this does not relate to these samples.

SHIVANGISINGH1 commented 2 years ago

I am also facing CORS error how do I solve it.

mehmetaliayhan6 commented 2 years ago

Shivangi Singh @.***>, 26 Haz 2022 Paz, 18:36 tarihinde şunu yazdı:

I am also facing CORS error how do I solve it.

— Reply to this email directly, view it on GitHub https://github.com/twitterdev/Twitter-API-v2-sample-code/issues/32#issuecomment-1166566773, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYXQJTR5EP46AWUEKBR7CPDVRB2JVANCNFSM43OFJP3A . You are receiving this because you are subscribed to this thread.Message ID: @.*** com>

-- MEHMET ALİ AYHAN http://www.mehmetaliayhan.com.tr

andypiper commented 2 years ago

The Twitter API does not support CORS so you will have to call it from a server-side application rather than directly from JavaScript in the browser.

SHIVANGISINGH1 commented 2 years ago

The Twitter API does not support CORS so you will have to call it from a server-side application rather than directly from JavaScript in the browser.

Okay, I'll try on node thanks :)