我在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>


上面的代码抛出错误,因为


有什么我想念的吗?

最佳答案

与JS无关。您必须在服务器标头中添加跨源。
您必须在服务器标头中执行类似的操作

 header("Access-Control-Allow-Origin: *")

07-24 18:38
查看更多