我一直在尝试在我的React JS应用程序中实现Watson PersonalityInsightsV3 API。为了避免使用凭证时出现的CORS错误,我让flask/python服务器请求令牌。然后,我在React JS文件中使用fetch来接收令牌,并尝试将其传递给我的Watson配置文件请求。尽管如此,我仍然收到CORS错误,并且不确定如何使用令牌完成请求。
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) };发布于 2018-02-09 06:18:24
根据文档,这可能是不可能的:https://www.npmjs.com/package/watson-developer-cloud#client-side-usage
我不知道在Py中流行的包是什么,但请查看express-http-proxy。
https://stackoverflow.com/questions/48687834
复制相似问题