Embed a Video in a post in SharePoint Server 2013

Steps

Open Visual Studio in your system

Select Console Applciation template and give as name .
 
Add a Microsoft.Cleint Assembly refrence file in right side refrence tab in visual studio.

Replace Program.cs with the source code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using Microsoft.SharePoint.Client;  
  7. using Microsoft.SharePoint.Client.Social;  
  8. namespace EmbedVideoInPost  
  9. {  
  10.     class Program  
  11.     {  
  12.         static void Main(string[] args)  
  13.         {  
  14.             // Replace the following placeholder values with the actual values.  
  15.             const string serverUrl = "http://gauti.sharepoint.com/sp";  
  16.             const string videoUrl = "http://gauti.sharepoint.com/Asset%20Library/fileName?Web=1";  
  17.   
  18.             try  
  19.             {  
  20.   
  21.                 // Get the context and the SocialFeedManager instance.  
  22.                 ClientContext clientContext = new ClientContext(serverUrl);  
  23.                 SocialFeedManager feedManager = new SocialFeedManager(clientContext);  
  24.   
  25.                 // Get the video attachment from the server.  
  26.                 ClientResult<SocialAttachment> attachment = feedManager.GetPreview(videoUrl);  
  27.                 clientContext.ExecuteQuery();  
  28.   
  29.                 // Define properties for the post and add the attachment.  
  30.                 SocialPostCreationData postCreationData = new SocialPostCreationData();  
  31.                 postCreationData.ContentText = "Look at this!";  
  32.                 postCreationData.Attachment = attachment.Value;  
  33.   
  34.                 // Publish the post. This is a root post to the user's feed, so specify  
  35.                 // null for the targetId parameter.  
  36.                 feedManager.CreatePost(null, postCreationData);  
  37.                 clientContext.ExecuteQuery();  
  38.   
  39.                 Console.Write("The post was published.");  
  40.                 Console.ReadLine();  
  41.             }  
  42.             catch (Exception ex)  
  43.             {  
  44.                 Console.Write("Error publishing the post: " + ex.Message);  
  45.                 Console.ReadLine();  
  46.             }  
  47.         }  
  48.     }  
  49. }