-->

Yammer Open Graph API Error 400

2019-05-31 17:58发布

问题:

I'm trying to write to the Yammer Activity Feed using Open Graph but I get 400 Bad Request Error. I'm wondering if the url or data is wrong.

function postToActivity() {
    yam.getLoginStatus( function(response) {
        if (response.authResponse) {
            yam.request(
              { url: "https://api.yammer.com/api/v1/activity.json" //note:  the endpoint is api.yammer...
              , method: "POST"
              , data: {
                  "activity" : {
                    "actor" : {
                        "name" : "Ken Domen",
                        "email" : "ken.domen@nike.com",
                        "action" : "like",
                        "object" : {
                            "url" : "http://www.google.com",
                            "title" : "Test"
                         }
                     }
                  }
                }
              , success: function (msg) {
                    alert("Post was Successful!: " + msg.messages[0].id); //id of new message
              }
              , error: function (msg) { alert("Post was Unsuccessful..." + msg); }
              }
            );
        } else {
            yam.login( function (response) {
               //nothing
            });
        }
    });
}

回答1:

Well, this works for me:

Create an Open Graph page:

yam.platform.request({
        url: "https://api.yammer.com/api/v1/activity.json",
        method: "POST",
        data: {
            "activity": {
                "actor": { "name": "my name", "email": "my email" },
                "action": "create",
                "object": { "url": "http://google.is", "title": "the page title"},
                "type": "url"
            }
        },
        success: function (res) { 
            alert("The request was successful.");
            console.dir(res);
        },
        error: function (res) {
            alert("There was an error with the request.");
            console.log(res)
        }
    })

Post message to the open graph page:

yam.platform.request({
        url: "https://api.yammer.com/api/v1/messages.json",
        method: "POST",
        data: {
          "body" : "Message body",
          "group_id": "grup id, i.e. 12345678",
          "og_url": "http://google.is"

        },
        success: function (res) { //print message response information to the console
            alert("The request was successful.");
            console.dir(res);
        },
        error: function (res) {
            alert("There was an error with the request.");
            console.log(res)
        }
    })


回答2:

I was having the same 400 error. In my case solution was very simply. I was using for the group_id the name of the group, and not the group_id.

You can get the group_id pointing your browser to the group you're interested in. In the URL parameters you'll have: ?type=in_group&feedId=3028738 the feedId is the group_id.

I corrected this and started to work perfectly.

I'm not saying this might be your case, but hope it helps.