在Instagram中搜索图像与图像ID

时间:2015-06-11 18:56:42

标签: c# instagram

我知道如何从具有特定主题标签的Instagram下载图像。我在下面从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));
        }

但我想知道如何通过提供imageid来搜索Instagram中的图像(如果它们存在与否)?

1 个答案:

答案 0 :(得分:1)

使用此API通过image_id获取图像数据:

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

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