search image in instagram with image id

939 Views Asked by At

I know how to download image from instagram with specific hashtags. I do below to download images from instagram

string[] splittedHashTags = hashtags.Split(',');
        foreach (string tag in splittedHashTags)
        {
            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}", tag, 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");

                        co
                        var imageId = image.SelectToken("id");
                        double imageCreatedTime = image.SelectToken("created_time").Value<double>();

                        DateTime dtImgCreatedTime = UnixTimeStampToDateTime(imageCreatedTime);



                        var webClient = new WebClient();
                        byte[] imageBytes = webClient.DownloadData(imageUrl);

                          SPSite site = new SPSite(microSiteUrl);

                                                                                   }
                    }


                }




            }
            while (!String.IsNullOrEmpty(nextPageUrl));
        }

But i would like to know how can i search images in instagram if they exist or not by providing imageid?

1

There are 1 best solutions below

0
On

use this API for get image data by image_id:

https://api.instagram.com/v1/media/{media-id}?access_token=ACCESS-TOKEN

https://instagram.com/developer/endpoints/media/#get_media