I have been attempting to implement the Watson PersonalityInsightsV3 API into my React JS app. In order to circumvent the CORS error that arises when using credentials I have a flask/python server making a request for the token. I then use fetch inside my React JS files to receive the token and attempt to pass it to my Watson profile request. I am still getting the CORS error despite this and am not sure how to complete the request with the token.
try { axios.get('http://project1-m6.c9users.io:8080/token')
.then(result => { console.log('AAA ' + result.data)
var PersonalityInsightsV3 = require('watson-developer-cloud/personality-insights/v3');
var personality_insights = new PersonalityInsightsV3({
username: 'myname',
password: 'mypassword',
version_date: '2017-10-13',
headers: { 'X-Watson-Authorization-Token': result.data }
});
personality_insights.profile(
{
content: input,
content_type: 'text/plain',
consumption_preferences: true,
raw_scores: true
},
function(err, response) {
if (err) {
console.log('error:', err);
} else {
console.log(JSON.stringify(response, null, 2));
_this.props.history.push(
{pathname: '/personality', state: {result:JSON.stringify(response, null, 3)}})
}
}
);
}
);
} catch(e) { console.log(e) };