首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React JS - IBM Watson Personality InsightsV3令牌身份验证- CORS错误

React JS - IBM Watson Personality InsightsV3令牌身份验证- CORS错误
EN

Stack Overflow用户
提问于 2018-02-08 22:28:34
回答 1查看 196关注 0票数 0

我一直在尝试在我的React JS应用程序中实现Watson PersonalityInsightsV3 API。为了避免使用凭证时出现的CORS错误,我让flask/python服务器请求令牌。然后,我在React JS文件中使用fetch来接收令牌,并尝试将其传递给我的Watson配置文件请求。尽管如此,我仍然收到CORS错误,并且不确定如何使用令牌完成请求。

代码语言:javascript
复制
 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) };
EN

回答 1

Stack Overflow用户

发布于 2018-02-09 06:18:24

根据文档,这可能是不可能的:https://www.npmjs.com/package/watson-developer-cloud#client-side-usage

我不知道在Py中流行的包是什么,但请查看express-http-proxy

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48687834

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档