我試圖根據這裏的指令製作Yammer API請求:https://developer.yammer.com/yammer-sdks/#javascript-sdk。當我運行這個例子:Yammer 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")
}
}
);
我做了在本地主機上,我收到以下錯誤:
"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有相同的問題,並能夠解決它。 。
感謝
這是排序,整個JavaScript起源一方在Yammer它有點片狀,但最終我得到它的工作 – eloleon
任何提示你如何使它的工作?也許你可以回答你自己的問題 – pcv
嘿pcv。我在下一個答案中回答了這個問題:'實際'錯誤'是由於他們的錯誤文檔造成的。 REST端點是api.yammer.com/api/而不是www.yammer.com/api'。謝謝 – eloleon