【发布时间】:2019-12-15 07:08:18
【问题描述】:
我在“我的应用”中创建了一个 Yammer 应用,并将我的 Javascript 源设置为我的本地开发 URL:
在我的 React 应用程序中,我正在尝试使用 Fetch API 来获取一些数据。例如:
const url = 'https://www.yammer.com/api/v1/messages/following.json';
const options = {
method: 'GET',
mode: 'cors',
headers: {
'Authorization': `Bearer ${process.env.REACT_APP_YAMMER_ACCESS_TOKEN}`,
}
};
fetch(url, options).then(function(response) {
console.log(response);
return response.json();
}).then(function(json) {
console.log(json);
});
我收到 CORS 错误:
访问获取 'https://www.yammer.com/api/v1/messages/following.json' 来自原点 'http://localhost:3000' 已被 CORS 策略阻止:响应 预检请求未通过访问控制检查:否 请求中存在“Access-Control-Allow-Origin”标头 资源。如果不透明的响应满足您的需求,请设置请求的 模式为“no-cors”以获取禁用 CORS 的资源。
我在 Yammer 仪表板中设置了我的 Javascript 源,并且在我的获取请求中将模式设置为 CORS。我错过了什么?
【问题讨论】:
-
这对你有用吗?上述问题有什么解决办法吗?