Instagram

Feed, 12 billeder 4 pr. række, boxed:

Error executing template "Designs/Iris/Paragraph/I_InstagramFeed.cshtml"
System.Net.WebException: The remote server returned an error: (404) Not Found.
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   at System.Net.WebClient.DownloadString(Uri address)
   at CompiledRazorTemplates.Dynamic.RazorEngine_50b4e7137a2b42fea3aa6ba0f1690267.InstagramProgram.GetInstagramData(String myUri) in D:\dynamicweb.net\Solutions\Buchs\buchsdev1.dw9.dynamicweb-cms.com\Files\Templates\Designs\Iris\Paragraph\I_InstagramFeed.cshtml:line 331
   at CompiledRazorTemplates.Dynamic.RazorEngine_50b4e7137a2b42fea3aa6ba0f1690267.Execute() in D:\dynamicweb.net\Solutions\Buchs\buchsdev1.dw9.dynamicweb-cms.com\Files\Templates\Designs\Iris\Paragraph\I_InstagramFeed.cshtml:line 297
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @using System.Net; @using Newtonsoft.Json; @using Newtonsoft.Json.Linq; @using System.Runtime.Caching; @{ 2 init(); 3 4 } 5 6 @functions { 7 private string currentGroupType { get; set; } 8 9 public void init() 10 { 11 string isFirst = GetString("ParagraphContainerIsFirst"); 12 string groupStart = GetString("Item.BreakoutSettings.StartGroup"); 13 14 if (isFirst == "True" && groupStart == "False"){ 15 currentGroupType = Dynamicweb.Core.Converter.ToString(System.Web.HttpContext.Current.Items["currentGroupType"]); 16 } 17 18 if (groupStart == "True"){ 19 currentGroupType = Dynamicweb.Core.Converter.ToString(System.Web.HttpContext.Current.Items["currentGroupType"]); 20 string newGroupType = GetString("Item.BreakoutSettings.GroupType.Value"); 21 System.Web.HttpContext.Current.Items["currentGroupType"] = newGroupType; 22 } 23 24 else { 25 currentGroupType = Dynamicweb.Core.Converter.ToString(System.Web.HttpContext.Current.Items["currentGroupType"]); 26 System.Web.HttpContext.Current.Items["currentGroupType"] = currentGroupType; 27 } 28 } 29 30 31 public string NewGroup(string theGroupClass) 32 { 33 string itemType = Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Item.SystemName); 34 35 string rowAddHorizontalMargin = ""; 36 if (GetBoolean("Item.Layout.ShowAsBox") == true && GetBoolean("Item.Layout.RemoveHorizontalMargin") != true) { 37 rowAddHorizontalMargin = " row-add-hor-margin"; 38 } 39 string groupTextColorTheme = " dark-text"; 40 if (GetString("Item.BreakoutSettings.GroupTextColorTheme") == "bright") { 41 groupTextColorTheme = " bright-text"; 42 } 43 string groupPadding = " no-margins"; 44 if (!string.IsNullOrWhiteSpace(GetString("Item.BreakoutSettings.Margin"))) { 45 groupPadding = " " + GetString("Item.BreakoutSettings.Margin").Replace(","," "); 46 } 47 string groupClass = theGroupClass + groupTextColorTheme + groupPadding; 48 string isFirst = GetString("ParagraphContainerIsFirst"); 49 string groupStart = GetString("Item.BreakoutSettings.StartGroup"); 50 string contentPlaceholder = GetString("ParagraphContainer"); 51 52 if (isFirst == "True" && groupStart == "False" && contentPlaceholder != "menuwrap"){ 53 System.Web.HttpContext.Current.Items["currentGroupType"] = "full"; 54 return "<div class=\"container-fluid\"><div class=\"row\">"; 55 } 56 if (isFirst == "True" && groupStart == "False" && contentPlaceholder == "menuwrap"){ 57 System.Web.HttpContext.Current.Items["currentGroupType"] = "constrained"; 58 return "<div class=\"container-fluid\"><div class=\"container\"><div class=\"row\">"; 59 } 60 61 string groupStyles = ""; 62 string groupBgColor = ""; 63 string groupBgImg = ""; 64 if (!string.IsNullOrWhiteSpace(GetString("Item.BreakoutSettings.BackgroundColor"))) { 65 groupBgColor = "background-color:" + GetString("Item.BreakoutSettings.BackgroundColor") + ";"; 66 } 67 if (!string.IsNullOrWhiteSpace(GetString("Item.BreakoutSettings.BackgroundImage"))) { 68 groupBgImg = "background-image: url('" + GetString("Item.BreakoutSettings.BackgroundImage") + "');"; 69 } 70 groupStyles = " style=\"" + groupBgColor + groupBgImg + "\""; 71 72 if (isFirst == "True" && groupStart == "True" && contentPlaceholder != "menuwrap"){ 73 string newGroup = GetString("Item.BreakoutSettings.GroupType.Value"); 74 currentGroupType = newGroup; 75 if (currentGroupType == "full") 76 { 77 if (newGroup == "full") { 78 return "<div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"row\">"; 79 } 80 if (newGroup == "constrained") { 81 return "<div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"container\"><div class=\"row" + rowAddHorizontalMargin + "\">"; 82 } 83 else { 84 return string.Empty; 85 } 86 } 87 88 if (currentGroupType == "constrained") 89 { 90 if (newGroup == "full") { 91 return "<div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"row\">"; 92 } 93 94 if (newGroup == "constrained") { 95 return "<div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"container\"><div class=\"row" + rowAddHorizontalMargin + "\">"; 96 } 97 98 else { 99 return string.Empty; 100 } 101 102 } 103 else { 104 return string.Empty; 105 } 106 } 107 108 if (isFirst == "False" && groupStart == "True" && contentPlaceholder != "menuwrap"){ 109 string newGroup = GetString("Item.BreakoutSettings.GroupType.Value"); 110 111 if (currentGroupType == "full") 112 { 113 if (newGroup == "full") { 114 return "</div></div><div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"row\">"; 115 } 116 if (newGroup == "constrained") { 117 return "</div></div><div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"container\"><div class=\"row" + rowAddHorizontalMargin + "\">"; 118 } 119 else { 120 return string.Empty; 121 } 122 } 123 124 if (currentGroupType == "constrained") 125 { 126 if (newGroup == "full") { 127 return "</div></div></div><div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"row\">"; 128 } 129 130 if (newGroup == "constrained") { 131 return "</div></div></div><div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"container\"><div class=\"row" + rowAddHorizontalMargin + "\">"; 132 } 133 134 else { 135 return string.Empty; 136 } 137 138 } 139 else { 140 return string.Empty; 141 } 142 } 143 144 if (isFirst == "True" && groupStart == "True" && contentPlaceholder == "menuwrap"){ 145 string newGroup = "constrained"; 146 System.Web.HttpContext.Current.Items["currentGroupType"] = "constrained"; 147 currentGroupType = "constrained"; 148 149 if (currentGroupType == "constrained") 150 { 151 152 if (newGroup == "constrained") { 153 string navAlign = Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Area.Item["ShowSideNav"]); 154 string blogByline = ""; 155 156 if (itemType == "I_BlogCategory" || itemType == "I_BlogPost"){ 157 navAlign = "right"; 158 } 159 160 if (itemType == "I_BlogPost"){ 161 string author = Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Item["Author"]) != "" ? Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Item["Author"]) + ", " : ""; 162 string date = Dynamicweb.Core.Converter.ToDateTime(Dynamicweb.Frontend.PageView.Current().Item["Date"]).ToLongDateString(); 163 blogByline = "<div class=\"col-xs-12 blog-byline\">" + author + date + "</div>"; 164 } 165 166 167 168 169 int navCols = Dynamicweb.Core.Converter.ToInt32(Dynamicweb.Frontend.PageView.Current().Area.Item["SideNavCols"]); 170 int contentCols = 12 - navCols; 171 if (navAlign == "left"){ 172 navAlign = " col-md-push-" + Dynamicweb.Core.Converter.ToString(navCols); 173 } else { 174 navAlign = ""; 175 } 176 return "<div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"container\"><div class=\"row\"><div class=\"col-xs-12 col-md-" + Dynamicweb.Core.Converter.ToString(contentCols) + @navAlign + "\"><div class=\"row" + rowAddHorizontalMargin + "\">" + @blogByline; 177 } 178 179 else { 180 return string.Empty; 181 } 182 183 } 184 else { 185 return string.Empty; 186 } 187 } 188 189 else 190 { 191 return string.Empty; 192 } 193 } 194 195 public string LastGroup() 196 { 197 string isLast = GetString("ParagraphContainerIsLast"); 198 199 string itemType = Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Item.SystemName); 200 201 currentGroupType = Dynamicweb.Core.Converter.ToString(System.Web.HttpContext.Current.Items["currentGroupType"]); 202 if (isLast == "True"){ 203 string contentPlaceholder = GetString("ParagraphContainer"); 204 205 if (currentGroupType == "full" && contentPlaceholder != "menuwrap") 206 { 207 return "</div></div>"; 208 } 209 210 if (currentGroupType == "constrained" && contentPlaceholder != "menuwrap") 211 { 212 return "</div></div></div>"; 213 } 214 215 if (contentPlaceholder == "menuwrap") 216 { 217 string navAlign = Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Area.Item["ShowSideNav"]); 218 219 if (itemType == "I_BlogCategory" || itemType == "I_BlogPost"){ 220 navAlign = "right"; 221 } 222 223 int navCols = Dynamicweb.Core.Converter.ToInt32(Dynamicweb.Frontend.PageView.Current().Area.Item["SideNavCols"]); 224 int contentCols = 12 - navCols; 225 string navClass = " right-nav"; 226 if (navAlign == "left"){ 227 navClass = " left-nav"; 228 navAlign = " col-md-pull-" + Dynamicweb.Core.Converter.ToString(contentCols); 229 } else { 230 navAlign = ""; 231 } 232 return "</div></div><div class=\"col-md-" + Dynamicweb.Core.Converter.ToString(navCols) + @navClass + " hidden-xs hidden-sm" + @navAlign + " sidenav\">" + @RenderSnippet("sidenavheader") + @RenderSnippet("sidenav") + "<div id=\"sidenav-append\">" + @RenderSnippet("sidetags") + "</div>" + "</div></div></div></div>"; 233 } 234 235 else { 236 return string.Empty; 237 } 238 } 239 else 240 { 241 return string.Empty; 242 } 243 } 244 245 public string ColumnClass() 246 { 247 string mobile = GetString("Item.WidthSettings.WidthMobile") + " "; 248 string portrait = GetString("Item.WidthSettings.WidthTabletPortrait") + " "; 249 string landscape = GetString("Item.WidthSettings.WidthTabletLandscape") + " "; 250 string desktop = GetString("Item.WidthSettings.WidthDesktop"); 251 252 if (string.IsNullOrWhiteSpace(mobile)) { 253 mobile = "col-xs-12 "; 254 } 255 256 if (string.IsNullOrWhiteSpace(portrait)) { 257 portrait = ""; 258 } 259 if (string.IsNullOrWhiteSpace(landscape)) { 260 landscape = ""; 261 } 262 263 return mobile + portrait + landscape + desktop; 264 } 265 266 267 268 public string CenterBlock() 269 { 270 string centerBlock = ""; 271 if (GetString("Item.WidthSettings.CenterBlock") == "True") { 272 centerBlock = " center-col"; 273 } 274 return centerBlock; 275 } 276 277 278 } 279 @NewGroup("instagram-group") @{ string userid = GetString("Item.InstagramUserId"); string token = GetString("Item.InstagramAccessToken"); string quantity = GetString("Item.ImageQuantity"); string cols = GetString("Item.ImagesPerRow"); string myUri = "http://api.instagram.com/v1/users/" + userid + "/media/recent/?access_token=" + token + "&count=" + quantity; Rootobject root = JsonConvert.DeserializeObject<Rootobject>(InstagramProgram.GetInstagramData(myUri).ToString()); int i = 0; foreach (var data in root.data) { @:<div class="instacol col-xs-4 col-md-@cols"> var imgurl = data.images.standard_resolution.url; var imglink = data.link; var imgid = "instagram" + i; <a href="@imglink" target="_blank" title="Se på instagram" class="instagramimg @imgid lazy-normal" data-src="@imgurl"></a> @:</div> ++i; } } @LastGroup() @functions { public class InstagramProgram { public static object GetInstagramData(string myUri) { //string fromWhere = ""; var cachedDataString = MemoryCache.Default["InstagramData"]; if (cachedDataString == null) { //fromWhere = "Slooooow web"; WebClient client = new WebClient(); cachedDataString = client.DownloadString(myUri); MemoryCache.Default.Add("InstagramData", cachedDataString, DateTime.Now.AddMinutes(60)); } else { //fromWhere = "From cache..."; } return cachedDataString; } } public class Rootobject { public Pagination pagination { get; set; } public Datum[] data { get; set; } public Meta meta { get; set; } } public class Pagination { public string next_max_id { get; set; } public string next_url { get; set; } } public class Meta { public int code { get; set; } } public class Datum { public string id { get; set; } public User user { get; set; } public Images images { get; set; } public string created_time { get; set; } public object caption { get; set; } public bool user_has_liked { get; set; } public Likes likes { get; set; } public object[] tags { get; set; } public string filter { get; set; } public Comments comments { get; set; } public string type { get; set; } public string link { get; set; } public object location { get; set; } public object attribution { get; set; } public object[] users_in_photo { get; set; } } public class User { public string id { get; set; } public string full_name { get; set; } public string profile_picture { get; set; } public string username { get; set; } } public class Images { public Thumbnail thumbnail { get; set; } public Low_Resolution low_resolution { get; set; } public Standard_Resolution standard_resolution { get; set; } } public class Thumbnail { public int width { get; set; } public int height { get; set; } public string url { get; set; } } public class Low_Resolution { public int width { get; set; } public int height { get; set; } public string url { get; set; } } public class Standard_Resolution { public int width { get; set; } public int height { get; set; } public string url { get; set; } } public class Likes { public int count { get; set; } } public class Comments { public int count { get; set; } } }