我尝试在yammer的特定群组中关注代码。
function post() {
yam.getLoginStatus(
function(response) {
if (response.authResponse) {
console.log("logged in");
console.dir(response); //print user information to the console
yam.platform.request({
url: "https://www.yammer.com/api/v1/messages.json"
, method: "POST"
, data: { "body" : "Welcome to the Yammer API World.", "group_id":"xxxxxxx"}
, CORS: true
, dataType: "json"
, headers: { "Accept": "application/json; odata=verbose" }
, xhrFields: { withCredentials: true }
, success: function (msg) { alert("Post was Successful!: " + msg); }
, error: function (msg) { alert("Post was Unsuccessful..." + msg); }
});
}
else {
yam.platform.login(function (response) {
if (response.authResponse) {
console.dir(response);
yam.platform.request({
url: "https://www.yammer.com/api/v1/messages.json"
, method: "POST"
, data: { "body" : "Welcome to the Yammer API World.", "group_id":"xxxxxxx"}
, CORS: true
, dataType: "json"
, headers: { "Accept": "application/json; odata=verbose" }
, xhrFields: { withCredentials: true }
, success: function (msg) { alert("Post was Successful!: " + msg); }
, error: function (msg) { alert("Post was Unsuccessful..." + msg); }
});
}
});
}
});
}
在HTML文件中我添加了此代码
<script type="text/javascript" data-app-id="xxxxxxxxxxxxxxxx" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
上面的代码抛出错误为
我有什么遗漏吗?
答案 0 :(得分:1)
这与JS无关。您必须在服务器标头中添加交叉原点。 你必须在服务器头
中做这样的事情 header("Access-Control-Allow-Origin: *")
答案 1 :(得分:1)
我在网址上做了更改。更改之前我的网址是
url: "https://www.yammer.com/api/v1/messages.json"
现在我的网址是
url: "https://api.yammer.com/api/v1/messages.json"
工作正常
我的2天只有三个角色......