【问题标题】:How do I post in yammer specific group?如何在 yammer 特定组中发帖?
【发布时间】:2012-09-06 05:18:29
【问题描述】:

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

但我还没有找到一个明确的想法来发布到特定的组。

我正在使用下面的代码贴在墙上。

<!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。但是它只是通过 from 作为 embed-widget 发布在同一面墙上。

【问题讨论】:

    标签: yammer


    【解决方案1】:

    您必须在 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();
            }
        }
    

    【讨论】:

      【解决方案2】:

      这会将消息发布到特定组。 您应该传递组 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>
      

      【讨论】:

      • 有人能举出更复杂的例子吗?我想通过 messages.json API 发布视频,我想将缩略图和类型设置为视频。
      【解决方案3】:

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

      你可以直接从Nuget使用

      【讨论】:

      • 请添加更多详细信息,而不仅仅是链接。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-07
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      相关资源
      最近更新 更多