如何在yammer特定组中发帖?

时间:2012-09-06 05:18:30

标签: yammer

我浏览了yammer api并创建了一个简单的html,将Feed发布到墙上。

但我没有找到明确的想法发布到特定群体。

我正在使用以下代码在墙上发布。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org"/>
<title>A Yammer App</title>
<script src="https://assets.yammer.com/platform/yam.js" type="text/javascript">
</script>
<script type="text/javascript">
//<![CDATA[
  yam.config({appId: "hyB2pTvrL36Y50py8EWj6A"}); 
  //]]>
  </script>
<title>A Yammer App</title>
</head>
<body>
<button onclick='post()'>Post on Yammer!</button>
<script type="text/javascript">
//<![CDATA[
  function post() { yam.getLoginStatus( function(response) { if (response.authResponse) { alert(1); yam.request( { url: "https://www.yammer.com/api/v1/messages.json" , method: "POST" , data: { "body" : "HelloTest"} , success: function (msg) { alert("Post was Successful!: " + msg); } , error: function (msg) { alert("Post was Unsuccessful..." + msg); } } ); } else { alert(2); yam.login( function (response) { if (!response.authResponse) { yam.request( { url: "https://www.yammer.com/api/v1/messages.json" , method: "POST" , data: { "body" : "HelloTest"} , success: function (msg) { alert("Post was Successful!: " + msg); } , error: function (msg) { alert("Post was Unsuccessful..." + msg); } } ); } }); } }); } 
  //]]>
  </script>
<script src="https://assets.yammer.com/platform/yam.js" type="text/javascript">
</script>
<script type="text/javascript">
//<![CDATA[
  yam.config({appId: "hyB2pTvrL36Y50py8EWj6A"}); 
  //]]>
  </script>
<button onclick='post()'>Post on Yammer!</button>
<script type='' "text/javascript">
  function post() { yam.getLoginStatus( function(response) { if (response.authResponse) { alert(1); yam.request( { url: "https://www.yammer.com/api/v1/messages.json" , method: "POST" , data: { "body" : "HelloTest"} , success: function (msg) { alert("Post was Successful!: " + msg); } , error: function (msg) { alert("Post was Unsuccessful..." + msg); } } ); } else { alert(2); yam.login( function (response) { if (!response.authResponse) { yam.request( { url: "https://www.yammer.com/api/v1/messages.json" , method: "POST" , data: { "body" : "HelloTest"} , success: function (msg) { alert("Post was Successful!: " + msg); } , error: function (msg) { alert("Post was Unsuccessful..." + msg); } } ); } }); } }); } 
  </script>
</body>
</html>

有人可以指导我吗?

我已经使用组应用程序ID更改了应用程序ID。但是,它只是与embed-widget一起发布在同一个墙上。

enter image description here

3 个答案:

答案 0 :(得分:4)

您必须在API请求中包含组ID以发布消息..这是c#中的示例

        StringBuilder data = new StringBuilder();
        data.Append("body=" + System.Web.HttpUtility.UrlEncode(reply));
        // the below line has the group Id encoded into the URL 
        data.Append("&group_id=" + System.Web.HttpUtility.UrlEncode(groupId));
        //Create byte array of the data that is to be sent
        byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());

        //Set the content length in the request header
        request.ContentLength = byteData.Length;

        //write data
        using (Stream postStream = request.GetRequestStream())
        {
            postStream.Write(byteData, 0, byteData.Length);
        }

        JObject jsonObj = null;
        //Get response
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            //get the response stream
            StreamReader reader = new StreamReader(response.GetResponseStream());

            jsonObj = JObject.Parse(reader.ReadToEnd());

            //Console.WriteLine("Message posted successfully!!");
            return jsonObj["messages"][0]["id"].ToString();
        }
    }

答案 1 :(得分:1)

这会将消息发布到特定组。 您应该传递组ID。

 <script>
  yam.config({appId: "Your App ID"}); //Your APP ID
</script>


<button style="width:150px" onclick='post()'>Post</button>



<script>
function post() {
    yam.getLoginStatus( function(response) {
        if (response.authResponse) {
            yam.request(
              { url: "https://www.yammer.com/api/v1/messages.json"
              , method: "POST"
              , data: { "body" : "Posted to the group", "group_id":"UR GROUP ID"} // Pass ur Group ID here
              }
            );
        } else {
            yam.login( function (response) {
              if (!response.authResponse) {
                yam.request(
                  { url: "https://www.yammer.com/api/v1/messages.json"
                  , method: "POST"
                  , data: { "body" : "Posted to the group", "group_id":"UR GROPU ID"}
                  }
                );
              }
            });
        }
    });
}
</script>

答案 2 :(得分:0)

我写了一个小的API包装器:Yammer.SimpleAPI

您可以直接从Nuget

使用