【发布时间】:2014-07-26 02:41:00
【问题描述】:
我正在尝试按照此处的说明发出 Yammer API 请求:https://developer.yammer.com/yammer-sdks/#javascript-sdk。当我运行这个例子时:
yam.getLoginStatus(
function(response) {
if (response.authResponse) {
console.log("logged in");
yam.platform.request({
url: "https://www.yammer.com/api/v1/users.json", //this is one of many REST endpoints that are available
method: "GET",
data: { //use the data object literal to specify parameters, as documented in the REST API section of this developer site
"letter": "a",
"page": "2",
},
success: function (user) { //print message response information to the console
alert("The request was successful.");
console.dir(user);
},
error: function (user) {
alert("There was an error with the request.");
}
});
}
else {
alert("not logged in")
}
}
);
我在 localhost 上执行此操作,但出现以下错误:
"XMLHttpRequest cannot load https://www.yammer.com/api/v1/users.json?letter=a&page=2&_=1401954073159. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access."
知道如何解决这个问题吗?
还有一件事。我无法在其中指定其他标头,因为此调用是作为“OPTIONS”而不是“GET”请求方法执行的。
希望有人对 Yammer 最新 API 有同样的问题并能够解决它。
谢谢
【问题讨论】:
-
这是排序的,Yammer 上的整个 JavaScript Origin 端有点不稳定,但最后我让它工作了
-
关于你如何使它工作的任何提示?也许你可以回答你自己的问题
-
嘿pcv。我在下一个答案中回答了这个问题:'实际的'错误'是由他们的错误文档引起的。 REST 端点是 api.yammer.com/api/ 而不是 www.yammer.com/api'。谢谢
-
嗯,这对我不起作用。无论我使用 www.yammer.com 还是 api.yammer.com,我都会收到错误消息
标签: javascript ajax rest cors yammer