Exemple #1
0
        public static async Task PostActivity(ActivityEnvelope activityEnvelope)
        {
            //Post New Message
            string accessToken = await GetAccessToken();

            string requestUri = "https://www.yammer.com/api/v1/activity.json";

            HttpClient         client  = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUri);

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            string json = activityEnvelope.GetJSON();

            //string json = "{\"activity\":{\"actor\":{";
            //json += "\"name\":\"Scot Hillier\",\"email\":\"[email protected]\"}";
            //json += ",\"action\":\"create\",\"object\":{\"url\":\"http://c.s-microsoft.com/en-us/CMSImages/mslogo.png?version=856673f8-e6be-0476-6669-d5bf2300391d\",\"title\":\"";
            //json += title.Text;
            //json += "\"},\"message\":\"";
            //json += message.Text;
            //json += "\"}}";

            StringContent requestContent = new StringContent(json);

            request.Content = requestContent;
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            HttpResponseMessage response = await client.SendAsync(request);

            XElement root = Json2Xml(await response.Content.ReadAsStringAsync());
        }
        public static async Task PostActivity(ActivityEnvelope activityEnvelope)
        {

            //Post New Message
            string accessToken = await GetAccessToken();

            string requestUri = "https://www.yammer.com/api/v1/activity.json";

            HttpClient client = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUri);
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            string json = activityEnvelope.GetJSON();

            //string json = "{\"activity\":{\"actor\":{";
            //json += "\"name\":\"Scot Hillier\",\"email\":\"[email protected]\"}";
            //json += ",\"action\":\"create\",\"object\":{\"url\":\"http://c.s-microsoft.com/en-us/CMSImages/mslogo.png?version=856673f8-e6be-0476-6669-d5bf2300391d\",\"title\":\"";
            //json += title.Text;
            //json += "\"},\"message\":\"";
            //json += message.Text;
            //json += "\"}}";

            StringContent requestContent = new StringContent(json);
            request.Content = requestContent;
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            HttpResponseMessage response = await client.SendAsync(request);
            XElement root = Json2Xml(await response.Content.ReadAsStringAsync());

        }
        public async Task<ActionResult> Create(ActivityViewModel model)
        {
            ActivityEnvelope envelope = new ActivityEnvelope(model);

            if (Request.HttpMethod == "POST")
            {
                await YammerRepository.PostActivity(envelope);
                return Redirect("/");
            }
            else
            {
                return View(model);
            }
        }