【问题标题】:Yammer REST API - How can I fetch data from a different origin (CORS)?Yammer REST API - 如何从不同来源 (CORS) 获取数据?
【发布时间】:2019-12-15 07:08:18
【问题描述】:

我在“我的应用”中创建了一个 Yammer 应用,并将我的 Javascript 源设置为我的本地开发 URL:

http://localhost:3000

在我的 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。我错过了什么?

【问题讨论】:

  • 这对你有用吗?上述问题有什么解决办法吗?

标签: rest api cors yammer


【解决方案1】:

我得到了它使用不同的 URL:

const url = 'https://api.yammer.com/api/v1/messages.json';

我没有在任何地方看到此文档,但我看到有人在另一个 StackOverflow 帖子上引用它 here

【讨论】:

    猜你喜欢
    • 2014-09-13
    • 2019-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-24
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多