Пример #1
0
        //Get the most recent media published by the owner of the access_token.
        public async Task <Picture> getRecentImage()
        {
            string path = "https://api.instagram.com/v1/users/self/media/recent?access_token=" + Global.TOKEN;
            HttpResponseMessage response = await client.GetAsync(path);

            List <string> list       = new List <string>();
            string        jsonString = response.Content.ReadAsStringAsync().Result;

            Picture image = new Picture();

            if (response.IsSuccessStatusCode)
            {
                dynamic stuff = JObject.Parse(jsonString);
                var     v     = stuff["data"];
                JArray  v1    = JArray.Parse(v.ToString());
                if (v1.Count > 0)
                {
                    var standImage = v1[0]["images"]["standard_resolution"];
                    image = JsonConvert.DeserializeObject <Picture>(standImage.ToString());
                }
            }
            else
            {
                var       jsonError = response.Content.ReadAsStringAsync().Result;
                dynamic   error     = JObject.Parse(jsonError);
                ErrorAPis errorApis = JsonConvert.DeserializeObject <ErrorAPis>(error["meta"].ToString());
                throw new Exception(errorApis.error_message);
            }
            return(image);
        }
Пример #2
0
        //Get a list of users matching the query.
        public async Task <List <Profile> > searchUser(string userName)
        {
            string path = "https://api.instagram.com/v1/users/search?q=" + userName + "&access_token=" + Global.TOKEN;
            HttpResponseMessage response = await client.GetAsync(path);

            Profile        profile     = new Profile();
            List <Profile> listProfile = new List <Profile>();
            var            jsonString  = response.Content.ReadAsStringAsync().Result;

            if (response.IsSuccessStatusCode)
            {
                dynamic stuff = JObject.Parse(jsonString);
                foreach (var item in stuff["data"])
                {
                    profile = JsonConvert.DeserializeObject <Profile>(item.ToString());
                    listProfile.Add(profile);
                }
            }
            else
            {
                var       jsonError = response.Content.ReadAsStringAsync().Result;
                dynamic   error     = JObject.Parse(jsonError);
                ErrorAPis errorApis = JsonConvert.DeserializeObject <ErrorAPis>(error["meta"].ToString());
                throw new Exception(errorApis.error_message);
            }
            return(listProfile);
        }
Пример #3
0
        //Get profile about owner of the access_token.
        public async Task <Profile> getProfile()
        {
            string path = "https://api.instagram.com/v1/users/self/?access_token=" + Global.TOKEN;
            HttpResponseMessage response = await client.GetAsync(path);

            Profile profile    = new Profile();
            var     jsonString = response.Content.ReadAsStringAsync().Result;

            if (response.IsSuccessStatusCode)
            {
                dynamic stuff = JObject.Parse(jsonString);
                profile = JsonConvert.DeserializeObject <Profile>(stuff["data"].ToString());
            }
            else
            {
                var       jsonError = response.Content.ReadAsStringAsync().Result;
                dynamic   error     = JObject.Parse(jsonError);
                ErrorAPis errorApis = JsonConvert.DeserializeObject <ErrorAPis>(error["meta"].ToString());
                throw new Exception(errorApis.error_message);
            }
            return(profile);
        }