0

I tried following code post in a specific group in 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); }
                    });
                }
            });
        }
    });

}

in HTML file I have added this code

<script type="text/javascript" data-app-id="xxxxxxxxxxxxxxxx" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>

Code above throws error as enter image description here

Is there any thing I am missing in it?

sandeep.gosavi
  • 610
  • 2
  • 10
  • 27

3 Answers3

1

It is nothing to do with JS . you have to add cross origin in your server header. you have to do something like this in server header

 header("Access-Control-Allow-Origin: *")
Ashisha Nautiyal
  • 1,389
  • 2
  • 19
  • 39
1

I made changes in url. Before changes my url was

 url: "https://www.yammer.com/api/v1/messages.json"

Now my url is

url: "https://api.yammer.com/api/v1/messages.json"

It is working fine

Only three characters took my 2 days....

sandeep.gosavi
  • 610
  • 2
  • 10
  • 27
1

If it helps, there's a full sample code on how to post messages to a group in yammer here - http://blogs.technet.com/b/israelo/archive/2014/10/21/yammer-js-sdk-for-dummies.aspx

mr i.o
  • 952
  • 2
  • 10
  • 20