我正在尝试将MailChimp的API集成到我的React App中,这将允许用户授权其MailChimp帐户在我的应用程序中使用。我尚未找到关于它的教程,因此我正在关注仅使用express的本教程:https://www.codementor.io/mattgoldspink/integrate-mailchimp-with-nodejs-app-du10854xp
我已经通过Mailchimp设置了我的应用程序/我的客户端密码/客户端ID,等等:
重定向URI
```http://127.0.0.1:3001/mailchimp/auth/callback````
我保留了与本教程相同的明确代码,只是我将客户端密码放入.env文件中。
server.js
const querystring = require('querystring');
const mailchimpClientId = `${process.env.MC_CLIENT}`
app.get('/mailchimp/auth/authorize',function (req,res) {
res.redirect('https://login.mailchimp.com/oauth2/authorize?' +
querystring.stringify({
'response_type': 'code','client_id': mailchimpClientId,'redirect_uri': 'http://127.0.0.1:3000/mailchimp/auth/callback'
}));
});
但是,在本教程中,回调函数位于这样编写的HTML文件中:
<!doctype html>
<html>
<head>
<title>Integrate MailChimp</title>
</head>
<body>
<a class="btn btn-primary" href="/mailchimp/auth/authorize">Connect with MailChimp</a>
</body>
</html>
我已经添加了此内容(使用JSX语法):
MailChimp.jsx
class MailChimp extends Component {
render() {
return (
<div>
<h1>MailChimp Auth</h1>
<a href={'http://127.0.0.1:3000/mailchimp/auth/authorize'}>Mailchimp</a>
</div >
)
}
}
export default withRouter(MailChimp);
在我的React App的路由localhost:3001/mailchimp
中单击该链接时,我被发送到mailchimp,在其中我成功地使用我的帐户登录(没有一个请求许可的帐户),然后我返回了React App。
但是,出现以下错误:
GET /mailchimp/auth/callback 404 2.818 ms - 162
Failed to load resource: the server responded with a status of 404 (Not Found)
我在网上搜了一下,试图找到一个使用React&Express for MailChimp Oauth进行应用授权的有效示例,但是我还没有找到。我的问题是,我是否在重定向中设置了错误,还是有更好的建议在React中处理此请求?