I have this code which loads images from Instagram.
public string giveInstagramImage()
{
string strtagName = "Snowy";
string strAccessToken = "<<REDACTED>>";
string nextPageUrl = null;
string imageUrl = null;
do
{
WebRequest webRequest = null;
if (webRequest == null && string.IsNullOrEmpty(nextPageUrl))
webRequest = HttpWebRequest.Create(String.Format("https://api.instagram.com/v1/tags/{0}/media/recent?access_token={1}", strtagName, strAccessToken));
else
webRequest = HttpWebRequest.Create(nextPageUrl);
var responseStream = webRequest.GetResponse().GetResponseStream();
Encoding encode = System.Text.Encoding.Default;
using (StreamReader reader = new StreamReader(responseStream, encode))
{
JToken token = JObject.Parse(reader.ReadToEnd());
var pagination = token.SelectToken("pagination");
if (pagination != null && pagination.SelectToken("next_url") != null)
{
nextPageUrl = pagination.SelectToken("next_url").ToString();
}
else
{
nextPageUrl = null;
}
var images = token.SelectToken("data").ToArray();
foreach (var image in images)
{
imageUrl = image.SelectToken("images").SelectToken("standard_resolution").SelectToken("url").ToString();
if (String.IsNullOrEmpty(imageUrl))
Console.WriteLine("broken image URL");
var imageResponse = HttpWebRequest.Create(imageUrl).GetResponse().GetResponseStream();
var imageId = image.SelectToken("id");
return imageUrl;
}
}
}
while (!String.IsNullOrEmpty(nextPageUrl));
return imageUrl;
}
Currently Instagram API gives me the top 20 images. What I need to do is load all images from the last 30 days.
How can we do it?