Yammer Open Graph API Error 400

五迷三道 提交于 2019-12-08 04:14:22

问题


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.



来源:https://stackoverflow.com/questions/24657648/yammer-open-graph-api-error-400

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!