I am trying to use Twitter API in my app.
When I run it from Postman, it works great.
However, when I run it from my app, using Google Chrome I get
XMLHttpRequest cannot load https://api.twitter.com/1.1/search/tweets.json?q=canada. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 400.
Here is my code for it
...
getTweets(hashtag : string){
var headers = new Headers();
headers.append('Authorization', 'Bearer AAAAAAAAAAAAAAAAAAAAAONruQAAAAAAfxQda4njz64axXN9sw4U0oU%3Dr1niTwKwXoOZXmZczDKgN0wWHWEMPrPcnXXMgVQhiTIzays7J');
var requestOptions = new MyRequest();
requestOptions.headers = headers;
return this.http.get('https://api.twitter.com/1.1/search/tweets.json?q=montreal', requestOptions);
}
}
class MyRequest implements RequestOptionsArgs {
public headers: Headers;
}