Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I gave up due my deadline, so I had to consume the JSON.</p> <p>Get the JSON</p> <pre><code> HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://api.instagram.com/v1/users/xxxxxx/media/recent?access_token=" + ConfigurationManager.AppSettings["instagramAccessToken"]); request.Method = "GET"; String json = String.Empty; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); json = reader.ReadToEnd(); reader.Close(); dataStream.Close(); } </code></pre> <p>Read it and insert in a database, using Linq to SQL:</p> <pre><code> dynamic dyn = JsonConvert.DeserializeObject(json); foreach (var data in dyn.data) { RES_PostInstagram reg = new RES_PostInstagram(); reg.filter = data.filter; reg.idPost = data.id; reg.image = data.images.standard_resolution.url; reg.link = data.link; reg.publicar = true; reg.thumbnail = data.images.thumbnail.url; reg.type = data.type; reg.created_time = this.UnixTimeStampToDateTime((double)data.created_time); if (data.caption != null) reg.caption = data.caption.text; foreach (string tag in data.tags) reg.tags += tag + ", "; // se o post nao existir no banco inserir RES_PostInstagram existe = (from p in this.ctx.RES_PostInstagrams where p.idPost == reg.idPost select p).FirstOrDefault(); if (existe == null) { this.ctx.RES_PostInstagrams.InsertOnSubmit(reg); this.ctx.SubmitChanges(); } } </code></pre> <p>Convert Unix Timestamp to DateTime:</p> <pre><code> public DateTime UnixTimeStampToDateTime(double unixTimeStamp) { // Unix timestamp is seconds past epoch System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0); dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime(); return dtDateTime; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload