Add Social Network sharing checkboxes on every new blogposts

Posted by Community Admin on 03-Aug-2018 10:18

Add Social Network sharing checkboxes on every new blogposts

All Replies

Posted by Community Admin on 01-Jul-2016 00:00

At the time of creating new blog post, is it possible that there should be a check-boxes available for social networking sites like Facebook, Twitter, Linked in etc. and the Selected check-boxes at the time of creating new blog-post the newly created blog-post should be automatically posted over that site ?

 

So, For this is there any inbuilt functionality available or need to make it custom. and if required to make it custom then which would be the steps please suggest.

 

Please look in to the attached image of FB post from Sitefinity. Developed functionality should post such kind of post automatically from newly created blog-post.

Posted by Community Admin on 06-Jul-2016 00:00

Hello Anand,

Currently, we do not have a built-in output pipe for Facebook which will allow you to post your news items or any content items from Sitefinity to Facebook.

What I can suggest is to use the built-in functionality of the Sitefinity feeds and create RSS feeds in Sitefinity that are populated for example by the Sitefinity news items content or Sitefinity blog posts. You can then import these feeds in Facebook, or the social network you want using third party tools. 

Alternatively you can create such functionality using the API of the respective social network. In that case you can subscribe for the IDataEvent (http://docs.sitefinity.com/for-developers-idataevent)  and when there is Create action of item type BlogPost , then to execute your logic to publish the Items.

We have also logged a feature request to have this functionality out of the box. Here is the link to the feedback portal where you can vote to increase the popularity of the feature request and track its progress.

I hope that the information above was useful.

Regards,
Svetoslav Manchev
Telerik by Progress

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 22-Jul-2016 00:00

After using of an IDataEvent & We fetching the value of custom fields, The code I have implemented for the FacebookPost was not able to post the blogPost over facebook.

The issue was it's not getting value of Request["Code"] from the facebook.

Code of Content_Action method :

private void Content_Action(IDataEvent @event)
        
            var action = @event.Action;
            var contentType = @event.ItemType;
            var itemId = @event.ItemId;
            var providerName = @event.ProviderName;
            var manager = ManagerBase.GetMappedManager(contentType, providerName);
             
            BlogsManager blogsManager = BlogsManager.GetManager();
            var currentBlogPost = blogsManager.GetBlogPosts().Where(b => b.Id == itemId).ToList();
 
            if (@event.Action == "Updated" && ((Telerik.Sitefinity.Modules.Blogs.BlogsManager)manager).ModuleName == "Blogs" && currentBlogPost.Count > 0)
            
                var currContext = HttpContext.Current;
                string fb = Convert.ToString(DataExtensions.GetValue(currentBlogPost.First(), "Facebook"));
                if (fb.ToString() == "True")
                
                    string fbPostMsg = "MVC Integration with Facebook. - Demo test for Sitefinity";
                    string fbPostDesc = "Lorem Ipsum is simply dummy ";
                    string fbPostUrl = "http://www.sitefinity.com/";
                    PostOverFacebook(fbPostMsg, fbPostDesc, fbPostUrl, currContext);
                
                string twitter = Convert.ToString(DataExtensions.GetValue(currentBlogPost.First(), "Twitter"));
                string linkedIn = Convert.ToString(DataExtensions.GetValue(currentBlogPost.First(), "LinkedIn"));
            
 
            var item = manager.GetItemOrDefault(contentType, itemId);
        

 

Code for share it over facebook :

 

private void PostOverFacebook(string fbPostMsg, string fbPostDesc, string fbPostUrl, HttpContext currContext)
    string app_id = "xxxxxxx";
    string app_secret = "xxxxxxxxxxxxxxxx";
    string scope = "publish_pages,publish_actions,manage_pages";
     
    if (currContext.Request["code"] == null)
    
        currContext.Response.Redirect(string.Format(
            "https://graph.facebook.com/oauth/authorize?client_id=0&redirect_uri=1&scope=2",
            app_id, currContext.Request.Url.AbsoluteUri, scope));
    
    else
    
        Dictionary<string, string> tokens = new Dictionary<string, string>();
 
        string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id=0&redirect_uri=1&scope=2&code=3&client_secret=4",
            app_id, currContext.Request.Url.AbsoluteUri, scope, currContext.Request["code"].ToString(), app_secret);
 
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
 
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        
            StreamReader reader = new StreamReader(response.GetResponseStream());
 
            string vals = reader.ReadToEnd();
 
            foreach (string token in vals.Split('&'))
            
                //meh.aspx?token1=steve&token2=jake&...
                tokens.Add(token.Substring(0, token.IndexOf("=")),
                    token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
            
        
 
        string access_token = tokens["access_token"];
 
        var client = new FacebookClient(access_token);
 
        client.Post("/439497246133618/feed", new
        
            message = fbPostMsg,
            description = fbPostDesc,
            link = fbPostUrl,
        );
    

 

Also it's found that after publish button clicked from blogPost, The Content_Action method called multiple times. So how to use this method for only one time post over facebook after publish button pressed

This thread is closed