Exemplo n.º 1
0
        public List <UserInfoObject> lookupUsers(string[] targets, bool isScreenName = false)
        {
            List <UserInfoObject> result = new List <UserInfoObject>();

            foreach (List <string> ts in targets.Select((x, i) => new { Index = i, Value = x }).GroupBy(x => x.Index / 100).Select(x => x.Select(v => v.Value).ToList()))
            {
                StringBuilder json = new StringBuilder();

                object obj;
                if (isScreenName)
                {
                    obj = new { screen_name = string.Join(",", ts), include_entities = false }
                }
                ;
                else
                {
                    obj = new { user_id = string.Join(",", ts), include_entities = false }
                };

                try
                {
                    byte[] buff = Encoding.UTF8.GetBytes(TwitterOAuth.ToString(obj));

                    HttpWebRequest req = OAuth.MakeRequest("POST", "https://api.twitter.com/1.1/users/lookup.json", obj);
                    req.GetRequestStream().Write(buff, 0, buff.Length);
                    Stream resStream = req.GetResponse().GetResponseStream();
                    if (resStream != null)
                    {
                        using (StreamReader reader = new StreamReader(resStream))
                            json.AppendLine(reader.ReadToEnd());
                    }
                }
                catch (WebException ex)
                {
                    Stream resStream = ex.Response?.GetResponseStream();
                    if (resStream != null)
                    {
                        using (StreamReader reader = new StreamReader(resStream))
                        {
                            string response = reader.ReadToEnd();
                            MainForm.Instance.Log(response);
                        }
                    }
                }

                if (json.Length > 0)
                {
                    result.AddRange(JsonConvert.DeserializeObject <List <UserInfoObject> >(json.ToString()));
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public UserInfoObject UnBlock(string id, bool isScreenName = false)
        {
            StringBuilder json = new StringBuilder();

            object obj;

            if (isScreenName)
            {
                obj = new { screen_name = id, include_entities = false, skip_status = true }
            }
            ;
            else
            {
                obj = new { user_id = id, include_entities = false, skip_status = true }
            };

            try
            {
                byte[] buff = Encoding.UTF8.GetBytes(TwitterOAuth.ToString(obj));

                HttpWebRequest req = OAuth.MakeRequest("POST", "https://api.twitter.com/1.1/blocks/destroy.json", obj);
                req.GetRequestStream().Write(buff, 0, buff.Length);
                Stream resStream = req.GetResponse().GetResponseStream();
                if (resStream != null)
                {
                    using (StreamReader reader = new StreamReader(resStream))
                        json.AppendLine(reader.ReadToEnd());
                }
            }
            catch (WebException ex)
            {
                Stream resStream = ex.Response?.GetResponseStream();
                if (resStream != null)
                {
                    using (StreamReader reader = new StreamReader(resStream))
                    {
                        string response = reader.ReadToEnd();
                        MainForm.Instance.Log(response);
                    }
                }
            }

            return(json.Length > 0 ? JsonConvert.DeserializeObject <UserInfoObject>(json.ToString()) : null);
        }
Exemplo n.º 3
0
        public UserInfoObject UnMute(string id)
        {
            StringBuilder json = new StringBuilder();
            object        obj  = new { user_id = id };

            try
            {
                byte[] buff = Encoding.UTF8.GetBytes(TwitterOAuth.ToString(obj));

                HttpWebRequest req = OAuth.MakeRequest("POST", "https://api.twitter.com/1.1/mutes/users/destroy.json", obj);
                req.GetRequestStream().Write(buff, 0, buff.Length);
                Stream resStream = req.GetResponse().GetResponseStream();
                if (resStream != null)
                {
                    using (StreamReader reader = new StreamReader(resStream))
                        json.AppendLine(reader.ReadToEnd());
                }
            }
            catch (WebException ex)
            {
                Stream resStream = ex.Response?.GetResponseStream();
                if (resStream != null)
                {
                    using (StreamReader reader = new StreamReader(resStream))
                    {
                        string response = reader.ReadToEnd();
                        MainForm.Instance.Log(response);
                        if (Regex.IsMatch(response, @"(?i)""code""\s*:\s*88"))
                        {
                            throw new RateLimitException {
                                      target = id
                            }
                        }
                        ;
                    }
                }
            }

            return(json.Length > 0 ? JsonConvert.DeserializeObject <UserInfoObject>(json.ToString()) : null);
        }
    }