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 も変更しましたが、埋め込みウィジェットと同じ壁に投稿されているだけです。

ここに画像の説明を入力

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 に答える