Surendra Sharma

Surendra Sharma

Search This Blog

Showing posts with label Youtube. Show all posts
Showing posts with label Youtube. Show all posts

Tuesday, December 5, 2023

My Sitecore Contributions for Year 2023

As the digital landscape continues to evolve, so does the realm of Sitecore development, with each passing year bringing new challenges, advancements, and opportunities. As I reflect on the strides made in 2023, I am thrilled to share my journey and contributions within the Sitecore community. Over the past year, my dedication to pushing the boundaries, exploring innovative solutions, and collaborating with fellow developers has led to a series of meaningful contributions that have enriched the Sitecore ecosystem. In this article, I aim to highlight some of my most impactful endeavors, shedding light on the tools, insights, and experiences that have shaped my involvement and growth within the vibrant world of Sitecore.

 

Around 80,000+ Blog views in 2023

As a testament to my commitment in delivering impactful content that connects with audiences, I am honored to achieve a milestone of 1,050,000+ total views on my blog articles, with approximately 80,000 views amassed solely in the year 2023. Over the past decade, I have remained steadfast in maintaining, curating, and sharing valuable Sitecore-related insights on my blog. Notably, my journey began with my inaugural Sitecore blog post published on June 5, 2013.

http://www.sitecorelessons.com/




Blog Analytics for 12 months
Blog Analytics for 12 months


SUG Pune : Emotion Recognition Model

Presented a webinar as a Speaker in SUG Pune forum and conducted session on - From dummies to pro Utilizing Sitecore Edge Powered Recommendations Enhanced by an Emotion Recognition Model

Link

Published 26 blog articles

Published 26 blog articles for year 2023 on my blog site http://www.sitecorelessons.com/ 


Link

Total 24 recorded videos on My Sitecore YouTube channel

Recorded 24 videos on YouTube for this year on Sitecore available in on my YouTube channel.

  1. ChatGPT with Sitecore
  2. Sitecore Transfer : Your Last Minute Content Publish Option
  3. Sitecore Mindmap
  4. Simplest way to sort child items in Sitecore
  5. OData Services in Sitecore
  6. 12 Approaches for Content Migration in Sitecore
  7. Fastest and best way to upload images in Sitecore
  8. Webhooks in Sitecore 10.3
  9. Sitecore PowerShell scripts as a datasource
  10. Sitecore Content Hub as a Secondary CMS : An Overview
  11. How To: Embed Sitecore 10.3 form to external website page
  12. Sitecore with CSharp REPL
  13. Poster : 20 Years of Sitecore Journey
  14. Sitecore SXA module: SmartFill
  15. 8 ways to Find and Replace text in Sitecore
  16. Moving from Sitecore XP to Sitecore XM cloud
  17. Sitecore Technology Radar
  18. 5 ways to set Alt text for images in Sitecore
  19. Funny observations in Sitecore XM Cloud
  20. Sitecore Public Feed Migration
  21. A Comics : What is Sitecore DAM?
  22. Sitecore CDP Comics
  23. When NOT to use Headless CMS
  24. Sitecore Comics

Link

SUG Bangalore - Sitecore Pipelines From dummies to pro

Speaker in SUG Bangalore and conducted session on - Sitecore Pipelines : From dummies to pro

Link

Speaker in SUGCON India 2023 Conference

I was a speaker in SUGCON India 2023 Conference and conducted session on "Utilizing Sitecore Edge-Powered Recommendations Enhanced by an Emotion Recognition Model" . Here is Recap summary of my blog for this 2 days event http://www.sitecorelessons.com/2023/08/recap-of-sugcon-india-2023.html 


Link

Speaker in Sitecore User Group Pune

Presented webinar in Sitecore User Group Pune on topic - Sitecore Pipelines : From Dummies To Pro

Link

Sitecore Public Feed Migration

Sitecore Director of Developer Relations - Jason St-Cyr mentioned my timely video for Nuget outage reference in LinkedIn post. Here is my YouTube video for the same https://www.youtube.com/watch?v=2sjaBSLrXnY

Link

Sitecore Digital Asset Management Comics

Created a comics on Sitecore Digital Asset Management.

Link

 

Speaker in SUG Bangalore Group

Delivered webinar in Sitecore User Group Bangalore on - 15 ways of Content Migration to Sitecore

Link

 

Sitecore Technology Radar

Created Sitecore Technology Radar which can help organizations stay informed about these changes and make informed decisions about which technologies to adopt, trial, assess, or hold

Link

 

Speaker in Sitecore User Group in Delhi NCR

Delivered a session on Sitecore Content Migration on 15 April at the Sitecore User Group in Delhi NCR

Link

Sitecore CDP Comics

I created a comics on Sitecore CDP.

Link

Poster for 20 Years of Sitecore Journey

Created a jumbo poster for showing the 20 years of Sitecore journey.

Link

Sitecore Hackathon 2023 - SmartFill

I successfully created a Sitecore SXA module - SmartFill for the Sitecore Content and Experience Editor as a part of Sitecore Hackathon 2023.

 YouTube link - http://www.sitecorelessons.com/2023/03/sitecore-hackathon-2023-smartfill.html 

Blog article link - https://www.youtube.com/watch?v=cUCQejpMqYE 


Link

Sitecore Comics

Created Sitecore comics which explain Content management systems in an engaging and entertaining way

Link

Sitecore Mindmap

I created a Sitecore Mindmap diagram for quick reference

Youtube link - https://www.youtube.com/watch?v=c_AYSyearOA 

Link

 

Friday, September 28, 2018

Manage Youtube videos from Sitecore

This is a series of 3 articles where I will show how you control Facebook, Twitter and Youtube feeds from Sitecore and display it on your web page.
 
In last 2 post, I showed how to manage Facebook feeds using Facebook graph API and Twitter Tweets by using its API.

In this post, we will check how to access and control Youtube video feeds from Sitecore. 

Youtube videos from Sitecore
Youtube videos from Sitecore


For this you need API keys from Google for using Youtube API. 

Implementation

Create Sitecore template having fields like

Sitecore fields for Youtube video feeds
Sitecore fields for Youtube video feeds

Code


Install Nuget package named “Google.Apis.YouTube.V3″ to your HELIX based feature project.

First we need to create Template mapping class for these Youtube fields as

namespace Sitecore.Feature.Social
{
    using Sitecore.Data;

    public struct Templates
    {
        public struct SocialFeedsManager
        {
            public static ID ID = new ID("{B1959961-A315-468D-8D03-CA50CB790C86}");
            public static ID ContentItemID = new ID("{EC8578D8-4C0F-413E-83F2-C9BA5B249E85}");


            public struct Fields
            {
            
                public static readonly ID YoutubeAPIKey = new ID("{D2B9B6B6-2A4C-4E7F-B63E-D9D119E599AA}");
                public static readonly ID YoutubeChannelId = new ID("{AEB5A02B-9CC8-4A30-92D6-63BA90F10C2B}");
                public static readonly ID YoutubeQueryPart = new ID("{BB545EE0-FFD7-4372-8D2B-AF36470A435C}");
                public static readonly ID YoutubePlatformName = new ID("{34465AAC-CB7A-4B39-96A5-2EB029C288D9}");
                public static readonly ID YoutubeFrom = new ID("{C1BE81E3-62E9-49A0-A805-F9A7A1B1B08D}");
                public static readonly ID YoutubeMaxFeedsInAll = new ID("{FAB9C465-C484-4928-8A89-C7191ADBCE61}");
                public static readonly ID YoutubeMaxFeeds = new ID("{E99D9E1D-D930-4244-B7A0-7C0E3923C44A}");
                public static readonly ID YoutubeIsActive = new ID("{D2508648-EB83-40A7-86F2-845EFA86A6F9}");            }
        }


    }
}

Create Model classes to holds values of Sitecore item fields values and JSON data return by Youtube for video feeds as
·         ChannelName – Enum for different social channel
·         YoutubeFeeds – Get video feeds from Youtube
·         SocialMediaFeed – Class to hold single video feed data from Youtube JSON data

using System.Collections.Generic;
using System.Linq;
using Google.Apis.YouTube.v3;
using Google.Apis.Services;

namespace Sitecore.Feature.Social.Models
{
    public class YoutubeFeeds
    {
        public List<SocialMediaFeed> GetYoutubeVideos(string apiKey, string queryPart, string channelId, string platformName, string from, int maxResult = 2)
        {
            YouTubeService yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = apiKey });

            var searchListRequest = yt.Search.List(queryPart);
            searchListRequest.MaxResults = maxResult;
            searchListRequest.Order = SearchResource.ListRequest.OrderEnum.Date;
            searchListRequest.ChannelId = channelId;
            var searchListResult = searchListRequest.Execute();

            var lstYoutubeFeeds = searchListResult.Items.Select(x => new SocialMediaFeed
            {
                FeedID = x.Id.VideoId.ToString(),
                PlatformName = platformName,
                Title = x.Snippet.Title,
                Description = x.Snippet.Description,
                ImageURL = (x.Snippet.Thumbnails.Medium ?? x.Snippet.Thumbnails.High ?? x.Snippet.Thumbnails.Standard ?? x.Snippet.Thumbnails.Default__).Url,
                FeedURL = "https://www.youtube.com/watch?v=" + x.Id.VideoId.ToString(),
                From = from,
                Timestamp = x.Snippet.PublishedAt.Value
            }).ToList();

            return lstYoutubeFeeds;
        }
    }
}

using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Sitecore.Data.Items;
using Sitecore.Foundation.SitecoreExtensions.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using static Sitecore.Feature.Social.Templates;

namespace Sitecore.Feature.Social.Models
{
    public enum ChannelName
    {
        All,
        Facebook,
        Twitter,
        Instagram,
        Youtube
    }

    /// <summary>
    /// Social Feeds Model for getting Sitecore fields data
    /// </summary>
    public class SocialFeedsManagerModel
    {

        //Youtube
        public string YoutubeAccessToken { get; set; }
        public string YoutubeAccessTokenSecret { get; set; }
        public string YoutubeConsumerKey { get; set; }
        public string YoutubeConsumerSecret { get; set; }
        public string YoutubePlatformName { get; set; }
        public int YoutubeMaxFeedsInAll { get; set; }
        public int YoutubeMaxFeeds { get; set; }
        public bool YoutubeIsActive { get; set; }

        public SocialFeedsManagerModel() { }

        public void InitializeData(Item dataSourceItem, ChannelName channelName)
        {
            if (channelName == ChannelName.Youtube || channelName == ChannelName.All)
            {
                //Youtube
                this.YoutubeIsActive = dataSourceItem.Fields[SocialFeedsManager.Fields.YoutubeIsActive].IsChecked();
                if (this.YoutubeIsActive)
                {
                    this.YoutubeAPIKey = dataSourceItem[SocialFeedsManager.Fields.YoutubeAPIKey];
                    this.YoutubeChannelId = dataSourceItem[SocialFeedsManager.Fields.YoutubeChannelId];
                    this.YoutubeFrom = dataSourceItem[SocialFeedsManager.Fields.YoutubeFrom];
                    this.YoutubeMaxFeeds = System.Convert.ToInt32(dataSourceItem[SocialFeedsManager.Fields.YoutubeMaxFeeds]);
                    this.YoutubeMaxFeedsInAll = System.Convert.ToInt32(dataSourceItem[SocialFeedsManager.Fields.YoutubeMaxFeedsInAll]);
                    this.YoutubePlatformName = dataSourceItem[SocialFeedsManager.Fields.YoutubePlatformName];
                    this.YoutubeQueryPart = dataSourceItem[SocialFeedsManager.Fields.YoutubeQueryPart];
                }
            }
        }
    }

    /// <summary>
    /// Model for Social Media Feeds returning as JSON
    /// </summary>
    public class SocialMediaFeed
    {
        public string FeedID { get; set; }
        public string PlatformName { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string ImageURL { get; set; }
        public string FeedURL { get; set; }
        public DateTime Timestamp { get; set; }
        public string From { get; set; }
    }
}

Below is Controller code for fetching video feeds from Youtube model class and then as per settings in Sitecore item, return JSONResult of Youtube Feeds which finally received by AJAX request to show it on page.

namespace Sitecore.Feature.Social.Controllers
{
    using Newtonsoft.Json;
    using Sitecore.Data.Items;
    using Sitecore.Feature.Social.Models;
    using Sitecore.Foundation.SitecoreExtensions.Extensions;
    using Sitecore.Mvc.Presentation;
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Security.Cryptography;
    using System.Text;
    using System.Web.Mvc;
    using System.Web.Script.Serialization;
    using static Sitecore.Feature.Social.Templates;

    public class SocialController : Controller
    {
        private List<SocialMediaFeed> lstSocialFeeds = null;

        public ActionResult GetSocialFeeds(string channelName, string token)
        {
            string result = "Error - ";

            if (string.IsNullOrEmpty(channelName) || string.IsNullOrEmpty(token) || !token.Equals("accesstoken"))
            {
                result += "Unauthorized request!!!";
            }

            channelName = channelName ?? "all";
            result = CollectSocialFeeds(channelName, result);

            if (lstSocialFeeds != null && lstSocialFeeds.Count > 0)
            {
                return Json(new { success = true, responseResult = lstSocialFeeds }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { success = false, responseResult = result }, JsonRequestBehavior.AllowGet);
            }

        }
        /// <summary>
        /// Collect all feeds in list
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private string CollectSocialFeeds(string channelName, string result)
        {
            try
            {
                SocialFeedsManagerModel _SocialFeedsManagerModel = new SocialFeedsManagerModel();

                Item dataSourceItem = null;

                if (RenderingContext.CurrentOrNull != null)
                {
                    var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
                    dataSourceItem = Sitecore.Context.Database.GetItem(dataSourceId);
                }

                if (!dataSourceItem?.IsDerived(Templates.SocialFeedsManager.ID) ?? true)
                {
                    dataSourceItem = Context.Database.GetItem(SocialFeedsManager.ContentItemID);
                }

                lstSocialFeeds = new List<SocialMediaFeed>();

                switch (channelName.ToLower())
                {                    
                    case "youtube":
                        {
                            _SocialFeedsManagerModel.InitializeData(dataSourceItem, ChannelName.Youtube);

                            if (_SocialFeedsManagerModel.YoutubeIsActive)
                            {
                                YoutubeFeeds youtube = new YoutubeFeeds();
                                lstSocialFeeds = youtube.GetYoutubeVideos(_SocialFeedsManagerModel.YoutubeAPIKey, _SocialFeedsManagerModel.YoutubeQueryPart
                                    , _SocialFeedsManagerModel.YoutubeChannelId, _SocialFeedsManagerModel.YoutubePlatformName, _SocialFeedsManagerModel.YoutubeFrom,
                                    _SocialFeedsManagerModel.YoutubeMaxFeeds);
                            }
                            else
                            {
                                result += " Youtube feeds are disabled.";
                            }
                            break;
                        }       
                    default:
                        {
                            result += " Invalid Social Media.";
                            lstSocialFeeds = null;
                            break;
                        }
                }
            }
            catch (Exception ex)
            {
                result += " Occurred." + ex.Message;
                lstSocialFeeds = null;
                string str = ex.Message;
            }

            return result;
        }
    }
}

Write AJAX script and view in HTML to load the feeds 

@model Sitecore.Feature.Social.Models.JSONOutput

<div id="SocialFeedsDiv">


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <script>


        $(document).ready(function () {
            var b = null;
            $("#all").click(function () {
                loadfeeds("All")
            });

            $("#Facebook").click(function () {
                loadfeeds("Facebook")
            });

            $("#Twitter").click(function () {
                loadfeeds("Twitter")
            });

            $("#Youtube").click(function () {
                loadfeeds("Youtube")
            });

            $("#Instagram").click(function () {
                loadfeeds("Instagram")
            });


            function loadfeeds(channelName) {
                $.get("/api/sitecore/social/GetSocialFeeds?channelName=" + channelName + "&token=accesstoken", function (data, status) {
                    var index = 1;
                    $("#feedlist").html("");
                    $.each(data.responseResult, function (i, field) {
                        var imageurl = "";
                        if (field.ImageURL !="" || field.ImageURL != null) {
                            imageurl = "ImageURL : <a href='" + field.FeedURL + "' ><img src='" + field.ImageURL + "' alt='" + field.Title + "' /> </a> <br>";
                        }
                        $("#feedlist").append(
                            "<li>Sr No :" + index + "<br>" +
                            "FeedID :" + field.FeedID + "<br>" +
                            "PlatformName :" + field.PlatformName + "<br>" +
                            "Title :" + field.Title + "<br>" +
                            "Description :" + field.Description + "<br>" + imageurl
                            +
                            "FeedURL :" + field.FeedURL + "<br>" +
                            "Timestamp :" + field.Timestamp + "<br>" +
                            "From :" + field.From + "<br><br><br>" + "</li>"
                        );
                        index++;
                    });
                });
            }
        });

    </script>

     <br />
    <a href="javascript:void(0)" id="all">All</a><br />
    <a href="javascript:void(0)" id="Facebook">Facebook</a><br />
    <a href="javascript:void(0)" id="Twitter">Twitter</a><br />
    <a href="javascript:void(0)" id="Youtube">Youtube</a><br />
    <a href="javascript:void(0)" id="Instagram">Instagram</a><br />

    <div id="feed">

    </div>

    <br />
    <br />

    <div id="HTMLfeed">
        <ul id="feedlist"></ul>


    </div>

</div>

We can access this action method from URL AJAX as

This will return JSON result which include individual feeds
{
    "success": true,
    "responseResult": [
        {
            "FeedID": "111111111_2222222",
            "PlatformName": "Youtube",
            "Title": "Title of video",
            "Description": " We all love free things. If you apply same concept on study, its great for professional life as well as for future",
            "ImageURL": "https://i.ztimg.com/vi/111111/default.jpg",
            "FeedURL": "https://www.youtube.com/watch?v=111111",
            "Timestamp": "/Date(1530689661000)/",
            "From": " Bill Gates"
        }
    ]
}

Once we have JSON, we can show it in page in any desired HTML format.
That’s it.

I hope you enjoy this Sitecore article. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.