Be part of our story @verpancom

Exception in template (\Designs\verpan\Paragraph\Instagram feed.cshtml): System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.eeabdaaaeebbbe.Execute()
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
at RazorEngine.Templating.TemplateService.Run(ITemplate template, DynamicViewBag viewBag)
at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName)
at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()
@inherits Co3.Espresso.Website.TemplateBases.Paragraphs.Carousel @using Dynamicweb.Content.Items @using System.Text @using System.Net @using System.IO @using Newtonsoft.Json @{string refreshTokenUrl ="https://graph.instagram.com/refresh_access_token";int fallbackFeedLimit = 12;int timestampLimit = 432000;int feedLimit = fallbackFeedLimit;string accessToken = string.Empty;bool showCaptions = false;string instagramParagraphItemSystemName = GetString("Item.SystemName");string instagramParagraphItemId = GetString("Item.Id"); string status = "";Item instagramItem = ItemManager.Storage.GetById( instagramParagraphItemSystemName, instagramParagraphItemId );if ( instagramItem != null ){int initialTimestamp = 0;int.TryParse( instagramItem["Timestamp"].ToString(), out initialTimestamp );DateTime lastUpdated;string lastUpdatedCheck = instagramItem["LastUpdated"] != null ? instagramItem["LastUpdated"].ToString() : DateTime.Now.ToString();DateTime.TryParse( lastUpdatedCheck, out lastUpdated );bool.TryParse(instagramItem["InstagramImageCaption"].ToString(), out showCaptions);if ( lastUpdated == null || lastUpdated == DateTime.MinValue ){lastUpdated = DateTime.Now;}string initialToken = instagramItem["InstagramAccessToken"].ToString();int.TryParse( instagramItem["InstagramLimit"].ToString(), out feedLimit );bool fetchNewToken = string.IsNullOrEmpty( initialToken ) == false && initialTimestamp < timestampLimit;if ( fetchNewToken == true ){string url = string.Format("{0}?access_token={1}&grant_type=ig_refresh_token", refreshTokenUrl, initialToken );HttpWebRequest request = ( HttpWebRequest ) WebRequest.Create( url );request.ContentType ="application/json; charset=utf-8";request.PreAuthenticate = true;HttpWebResponse response = request.GetResponse() as HttpWebResponse;if ( response != null ){using ( Stream responseStream = response.GetResponseStream() ){if ( responseStream != null ){StreamReader reader = new StreamReader( responseStream, Encoding.UTF8 );dynamic responds = JsonConvert.DeserializeObject( reader.ReadToEnd() );if ( responds.access_token != 0 ){accessToken = responds.access_token;instagramItem["InstagramAccessToken"] = accessToken;instagramItem["Timestamp"] = responds.expires_in;instagramItem["LastUpdated"] = DateTime.Now;}}}}}else{@* Update timestamp *@double diffBetweenNowAndLastUpdated = ( DateTime.Now - lastUpdated ).TotalSeconds;instagramItem["Timestamp"] = initialTimestamp - Math.Floor( diffBetweenNowAndLastUpdated );}@* Only save Item if lastUpdated is earlier date than today or new token has been fetched *@if ( fetchNewToken == true || lastUpdated.ToString("MM/dd/yyyy") != DateTime.Now.ToString("MM/dd/yyyy") ){instagramItem.Save();}@* Set initial access token from Item if empty *@if ( string.IsNullOrEmpty( accessToken ) == true ){accessToken = initialToken;}} }@if ( string.IsNullOrEmpty( accessToken ) == false ) {<section class="p mt-1 mb-1 col-12" id="instagram-feed-carousel-section" data-status="@status"><div id="instagram-feed-carousel-v2" class="carousel slide p-carousel instagram-feed" data-interval="0" data-pause="hover" data-ride="" data-keyboard="false" data-token="@accessToken" data-limit="@feedLimit" data-caption="@showCaptions"><div id="instagram-feed-v2" class="carousel-inner"></div><a class="carousel-control-prev" data-target="#instagram-feed-carousel"data-slide="prev"></a><a class="carousel-control-next" data-target="#instagram-feed-carousel"data-slide="next"></a></div></section> }
keyboard_arrow_up