0

我浏览了 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 发布在同一面墙上。

在此处输入图像描述

4

3 回答 3

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();
        }
    }
于 2012-10-20T11:58:24.897 回答
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>
于 2013-05-28T06:46:09.107 回答
0

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

您可以直接从Nuget使用

于 2013-05-22T10:19:37.510 回答