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

Yammer REST API for create status with topic and get back the topic Id

本文关键字:状态 Id 获取 API REST 用于 创建 Yammer      更新时间:2023-09-26

我想使用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。那么我该如何纠正。。??

提前感谢

您对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)
   }
});