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_164f61891ffb499581eb0a868977a958.InstagramProgram.GetInstagramData(String myUri) in E:\dynamicweb.net\Solutions\buchsdev1.net.dynamicweb-cms.com\Files\Templates\Designs\Iris\Paragraph\I_InstagramFeed.cshtml:line 331
   at CompiledRazorTemplates.Dynamic.RazorEngine_164f61891ffb499581eb0a868977a958.Execute() in E:\dynamicweb.net\Solutions\buchsdev1.net.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.b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @using System.Net; 2 @using Newtonsoft.Json; 3 @using Newtonsoft.Json.Linq; 4 @using System.Runtime.Caching; 5 6 @{ 7 init(); 8 9 } 10 11 @functions { 12 private string currentGroupType { get; set; } 13 14 public void init() 15 { 16 string isFirst = GetString("ParagraphContainerIsFirst"); 17 string groupStart = GetString("Item.BreakoutSettings.StartGroup"); 18 19 if (isFirst == "True" && groupStart == "False"){ 20 currentGroupType = Dynamicweb.Core.Converter.ToString(System.Web.HttpContext.Current.Items["currentGroupType"]); 21 } 22 23 if (groupStart == "True"){ 24 currentGroupType = Dynamicweb.Core.Converter.ToString(System.Web.HttpContext.Current.Items["currentGroupType"]); 25 string newGroupType = GetString("Item.BreakoutSettings.GroupType.Value"); 26 System.Web.HttpContext.Current.Items["currentGroupType"] = newGroupType; 27 } 28 29 else { 30 currentGroupType = Dynamicweb.Core.Converter.ToString(System.Web.HttpContext.Current.Items["currentGroupType"]); 31 System.Web.HttpContext.Current.Items["currentGroupType"] = currentGroupType; 32 } 33 } 34 35 36 public string NewGroup(string theGroupClass) 37 { 38 string itemType = Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Item.SystemName); 39 40 string rowAddHorizontalMargin = ""; 41 if (GetBoolean("Item.Layout.ShowAsBox") == true && GetBoolean("Item.Layout.RemoveHorizontalMargin") != true) { 42 rowAddHorizontalMargin = " row-add-hor-margin"; 43 } 44 string groupTextColorTheme = " dark-text"; 45 if (GetString("Item.BreakoutSettings.GroupTextColorTheme") == "bright") { 46 groupTextColorTheme = " bright-text"; 47 } 48 string groupPadding = " no-margins"; 49 if (!string.IsNullOrWhiteSpace(GetString("Item.BreakoutSettings.Margin"))) { 50 groupPadding = " " + GetString("Item.BreakoutSettings.Margin").Replace(","," "); 51 } 52 string groupClass = theGroupClass + groupTextColorTheme + groupPadding; 53 string isFirst = GetString("ParagraphContainerIsFirst"); 54 string groupStart = GetString("Item.BreakoutSettings.StartGroup"); 55 string contentPlaceholder = GetString("ParagraphContainer"); 56 57 if (isFirst == "True" && groupStart == "False" && contentPlaceholder != "menuwrap"){ 58 System.Web.HttpContext.Current.Items["currentGroupType"] = "full"; 59 return "<div class=\"container-fluid\"><div class=\"row\">"; 60 } 61 if (isFirst == "True" && groupStart == "False" && contentPlaceholder == "menuwrap"){ 62 System.Web.HttpContext.Current.Items["currentGroupType"] = "constrained"; 63 return "<div class=\"container-fluid\"><div class=\"container\"><div class=\"row\">"; 64 } 65 66 string groupStyles = ""; 67 string groupBgColor = ""; 68 string groupBgImg = ""; 69 if (!string.IsNullOrWhiteSpace(GetString("Item.BreakoutSettings.BackgroundColor"))) { 70 groupBgColor = "background-color:" + GetString("Item.BreakoutSettings.BackgroundColor") + ";"; 71 } 72 if (!string.IsNullOrWhiteSpace(GetString("Item.BreakoutSettings.BackgroundImage"))) { 73 groupBgImg = "background-image: url('" + GetString("Item.BreakoutSettings.BackgroundImage") + "');"; 74 } 75 groupStyles = " style=\"" + groupBgColor + groupBgImg + "\""; 76 77 if (isFirst == "True" && groupStart == "True" && contentPlaceholder != "menuwrap"){ 78 string newGroup = GetString("Item.BreakoutSettings.GroupType.Value"); 79 currentGroupType = newGroup; 80 if (currentGroupType == "full") 81 { 82 if (newGroup == "full") { 83 return "<div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"row\">"; 84 } 85 if (newGroup == "constrained") { 86 return "<div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"container\"><div class=\"row" + rowAddHorizontalMargin + "\">"; 87 } 88 else { 89 return string.Empty; 90 } 91 } 92 93 if (currentGroupType == "constrained") 94 { 95 if (newGroup == "full") { 96 return "<div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"row\">"; 97 } 98 99 if (newGroup == "constrained") { 100 return "<div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"container\"><div class=\"row" + rowAddHorizontalMargin + "\">"; 101 } 102 103 else { 104 return string.Empty; 105 } 106 107 } 108 else { 109 return string.Empty; 110 } 111 } 112 113 if (isFirst == "False" && groupStart == "True" && contentPlaceholder != "menuwrap"){ 114 string newGroup = GetString("Item.BreakoutSettings.GroupType.Value"); 115 116 if (currentGroupType == "full") 117 { 118 if (newGroup == "full") { 119 return "</div></div><div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"row\">"; 120 } 121 if (newGroup == "constrained") { 122 return "</div></div><div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"container\"><div class=\"row" + rowAddHorizontalMargin + "\">"; 123 } 124 else { 125 return string.Empty; 126 } 127 } 128 129 if (currentGroupType == "constrained") 130 { 131 if (newGroup == "full") { 132 return "</div></div></div><div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"row\">"; 133 } 134 135 if (newGroup == "constrained") { 136 return "</div></div></div><div class=\"container-fluid " + @groupClass + "\"" + @groupStyles + "><div class=\"container\"><div class=\"row" + rowAddHorizontalMargin + "\">"; 137 } 138 139 else { 140 return string.Empty; 141 } 142 143 } 144 else { 145 return string.Empty; 146 } 147 } 148 149 if (isFirst == "True" && groupStart == "True" && contentPlaceholder == "menuwrap"){ 150 string newGroup = "constrained"; 151 System.Web.HttpContext.Current.Items["currentGroupType"] = "constrained"; 152 currentGroupType = "constrained"; 153 154 if (currentGroupType == "constrained") 155 { 156 157 if (newGroup == "constrained") { 158 string navAlign = Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Area.Item["ShowSideNav"]); 159 string blogByline = ""; 160 161 if (itemType == "I_BlogCategory" || itemType == "I_BlogPost"){ 162 navAlign = "right"; 163 } 164 165 if (itemType == "I_BlogPost"){ 166 string author = Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Item["Author"]) != "" ? Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Item["Author"]) + ", " : ""; 167 string date = Dynamicweb.Core.Converter.ToDateTime(Dynamicweb.Frontend.PageView.Current().Item["Date"]).ToLongDateString(); 168 blogByline = "<div class=\"col-xs-12 blog-byline\">" + author + date + "</div>"; 169 } 170 171 172 173 174 int navCols = Dynamicweb.Core.Converter.ToInt32(Dynamicweb.Frontend.PageView.Current().Area.Item["SideNavCols"]); 175 int contentCols = 12 - navCols; 176 if (navAlign == "left"){ 177 navAlign = " col-md-push-" + Dynamicweb.Core.Converter.ToString(navCols); 178 } else { 179 navAlign = ""; 180 } 181 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; 182 } 183 184 else { 185 return string.Empty; 186 } 187 188 } 189 else { 190 return string.Empty; 191 } 192 } 193 194 else 195 { 196 return string.Empty; 197 } 198 } 199 200 public string LastGroup() 201 { 202 string isLast = GetString("ParagraphContainerIsLast"); 203 204 string itemType = Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Item.SystemName); 205 206 currentGroupType = Dynamicweb.Core.Converter.ToString(System.Web.HttpContext.Current.Items["currentGroupType"]); 207 if (isLast == "True"){ 208 string contentPlaceholder = GetString("ParagraphContainer"); 209 210 if (currentGroupType == "full" && contentPlaceholder != "menuwrap") 211 { 212 return "</div></div>"; 213 } 214 215 if (currentGroupType == "constrained" && contentPlaceholder != "menuwrap") 216 { 217 return "</div></div></div>"; 218 } 219 220 if (contentPlaceholder == "menuwrap") 221 { 222 string navAlign = Dynamicweb.Core.Converter.ToString(Dynamicweb.Frontend.PageView.Current().Area.Item["ShowSideNav"]); 223 224 if (itemType == "I_BlogCategory" || itemType == "I_BlogPost"){ 225 navAlign = "right"; 226 } 227 228 int navCols = Dynamicweb.Core.Converter.ToInt32(Dynamicweb.Frontend.PageView.Current().Area.Item["SideNavCols"]); 229 int contentCols = 12 - navCols; 230 string navClass = " right-nav"; 231 if (navAlign == "left"){ 232 navClass = " left-nav"; 233 navAlign = " col-md-pull-" + Dynamicweb.Core.Converter.ToString(contentCols); 234 } else { 235 navAlign = ""; 236 } 237 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>"; 238 } 239 240 else { 241 return string.Empty; 242 } 243 } 244 else 245 { 246 return string.Empty; 247 } 248 } 249 250 public string ColumnClass() 251 { 252 string mobile = GetString("Item.WidthSettings.WidthMobile") + " "; 253 string portrait = GetString("Item.WidthSettings.WidthTabletPortrait") + " "; 254 string landscape = GetString("Item.WidthSettings.WidthTabletLandscape") + " "; 255 string desktop = GetString("Item.WidthSettings.WidthDesktop"); 256 257 if (string.IsNullOrWhiteSpace(mobile)) { 258 mobile = "col-xs-12 "; 259 } 260 261 if (string.IsNullOrWhiteSpace(portrait)) { 262 portrait = ""; 263 } 264 if (string.IsNullOrWhiteSpace(landscape)) { 265 landscape = ""; 266 } 267 268 return mobile + portrait + landscape + desktop; 269 } 270 271 272 273 public string CenterBlock() 274 { 275 string centerBlock = ""; 276 if (GetString("Item.WidthSettings.CenterBlock") == "True") { 277 centerBlock = " center-col"; 278 } 279 return centerBlock; 280 } 281 282 283 } 284 285 @NewGroup("instagram-group") 286 287 @{ 288 289 290 291 string userid = GetString("Item.InstagramUserId"); 292 string token = GetString("Item.InstagramAccessToken"); 293 string quantity = GetString("Item.ImageQuantity"); 294 string cols = GetString("Item.ImagesPerRow"); 295 string myUri = "http://api.instagram.com/v1/users/" + userid + "/media/recent/?access_token=" + token + "&count=" + quantity; 296 297 Rootobject root = JsonConvert.DeserializeObject<Rootobject>(InstagramProgram.GetInstagramData(myUri).ToString()); 298 299 int i = 0; 300 foreach (var data in root.data) 301 { 302 303 @:<div class="instacol col-xs-4 [email protected]"> 304 305 var imgurl = data.images.standard_resolution.url; 306 var imglink = data.link; 307 var imgid = "instagram" + i; 308 <a href="@imglink" target="_blank" title="Se på instagram" class="instagramimg @imgid lazy-normal" data-src="@imgurl"></a> 309 310 @:</div> 311 312 ++i; 313 } 314 } 315 316 @LastGroup() 317 318 @functions { 319 public class InstagramProgram 320 { 321 public static object GetInstagramData(string myUri) 322 { 323 //string fromWhere = ""; 324 325 var cachedDataString = MemoryCache.Default["InstagramData"]; 326 327 if (cachedDataString == null) 328 { 329 //fromWhere = "Slooooow web"; 330 WebClient client = new WebClient(); 331 cachedDataString = client.DownloadString(myUri); 332 MemoryCache.Default.Add("InstagramData", cachedDataString, DateTime.Now.AddMinutes(60)); 333 } 334 else 335 { 336 //fromWhere = "From cache..."; 337 } 338 return cachedDataString; 339 } 340 } 341 342 343 public class Rootobject 344 { 345 public Pagination pagination { get; set; } 346 public Datum[] data { get; set; } 347 public Meta meta { get; set; } 348 } 349 350 public class Pagination 351 { 352 public string next_max_id { get; set; } 353 public string next_url { get; set; } 354 } 355 356 public class Meta 357 { 358 public int code { get; set; } 359 } 360 361 public class Datum 362 { 363 public string id { get; set; } 364 public User user { get; set; } 365 public Images images { get; set; } 366 public string created_time { get; set; } 367 public object caption { get; set; } 368 public bool user_has_liked { get; set; } 369 public Likes likes { get; set; } 370 public object[] tags { get; set; } 371 public string filter { get; set; } 372 public Comments comments { get; set; } 373 public string type { get; set; } 374 public string link { get; set; } 375 public object location { get; set; } 376 public object attribution { get; set; } 377 public object[] users_in_photo { get; set; } 378 } 379 380 public class User 381 { 382 public string id { get; set; } 383 public string full_name { get; set; } 384 public string profile_picture { get; set; } 385 public string username { get; set; } 386 } 387 388 public class Images 389 { 390 public Thumbnail thumbnail { get; set; } 391 public Low_Resolution low_resolution { get; set; } 392 public Standard_Resolution standard_resolution { get; set; } 393 } 394 395 public class Thumbnail 396 { 397 public int width { get; set; } 398 public int height { get; set; } 399 public string url { get; set; } 400 } 401 402 public class Low_Resolution 403 { 404 public int width { get; set; } 405 public int height { get; set; } 406 public string url { get; set; } 407 } 408 409 public class Standard_Resolution 410 { 411 public int width { get; set; } 412 public int height { get; set; } 413 public string url { get; set; } 414 } 415 416 public class Likes 417 { 418 public int count { get; set; } 419 } 420 421 public class Comments 422 { 423 public int count { get; set; } 424 } 425 426 }