Yammer REST API用于创建具有主题的状态并返回主题Id

时间:2014-09-24 12:28:36

标签: javascript status yammer

我想使用php和javascript创建yammer状态。这是我的示例代码 -

    <script type="text/javascript" data-app-id="client-id" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
    <span id="yammer-login"></span>
    <script> 
        $(function(){

            yam.connect.loginButton('#yammer-login', function (resp) { 
                if (resp.authResponse) {
                    yam.platform.request({
                        url: "messages.json",
                        method: "POST",
                        data: {
                            "body" : "Message body",
                            "group_id": "4728511", //group id
                            "topic1": "TestTopic1",
                            "og_url": "http://google.com"
                        },
                        success: function (res) { //print message response information to the console
                            alert("The request was successful.");
                            console.dir(res);
                            yam.platform.request({
                                url: "https://www.yammer.com/api/v1/search.json",
                                method: "GET",
                                data: {
                                    "search" : "TestTopic1"
                                },
                                success: function (data) { //print message response information to the console
                                    alert("The request was successful.");
                                    console.dir(data);
                                },
                                error: function (data) {
                                    alert("There was an error with the request.");
                                    console.log(data)
                                }
                            });
                        },
                        error: function (res) {
                            alert("There was an error with the request.");
                            console.dir(res);
                        }
                    });
                }
            });

状态在yammer上更新但显示错误,我也没有得到主题ID。 那怎么能纠正它呢?? ??

提前致谢

1 个答案:

答案 0 :(得分:0)

看起来你对search.json的第二次调用是罪魁祸首。使用JS SDK时,您应该直接调用REST资源,而不是放入URL(例如:www.yammer.com或api.yammer.com)。

您在第一次调用messages.json时已成功完成此操作,但应更新您对此的第二次调用:

yam.platform.request({
   url: "search.json",
   method: "GET",
   data: {
     "search" : "TestTopic1"
   },
   success: function (data) { //print message response information to the console
     alert("The request was successful.");
     console.dir(data);
   },
   error: function (data) {
     alert("There was an error with the request.");
     console.log(data)
   }
});