Hi Everyone,
I’m using the node-twitter package - https://www.npmjs.com/package/twitter and using React.
However I am getting an error in my console when making the GET request.
Is there any easy way to access the twitter API when using local host during development? I am only doing front end work at the moment.
Error:
Failed to load https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=nimaiwalsh: 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
my React component:
import React, { Component } from 'react';
const Twitter = require('twitter');
const client = new Twitter({
consumer_key: 'xxxxxxx',
consumer_secret: 'xxxxxxxx',
access_token_key: 'xxxxxxx',
access_token_secret: 'xxxxxxxx',
})
class TwitterFeed extends Component {
componentDidMount() {
const params = {screen_name: 'nimaiwalsh'};
client.get('statuses/user_timeline', params, function(error, tweets, response) {
if (!error) {
console.log(tweets);
} else {
throw error
}
});
}
render() {
return(
<div>Test twitter feed</div>
)
}
}
export default TwitterFeed
Thanks in advance