/// <summary> /// Gets last 20 users /// </summary> /// <param name="search">Search string</param> /// <returns>TwitterUserInfo list</returns> public List <TwitterUserInfo> FindUsers(string search) { const int pageRowCount = 20; const int pageNumber = 0; try { Twitterizer.OAuthTokens tokens = GetOAuthTokens(); UserSearchOptions options = new UserSearchOptions(); options.Page = pageNumber; options.NumberPerPage = pageRowCount; TwitterResponse <TwitterUserCollection> userResponse = TwitterUser.Search(tokens, search, options); if (userResponse.Result == RequestResult.Success) { TwitterUserCollection collection = userResponse.ResponseObject; return(MapUsers(userResponse.ResponseObject)); } else { throw CreateException(userResponse.Result, userResponse.ErrorMessage); } } catch (Exception ex) { log.Error(ex); throw; } }
public static void Test() { byte[] responseBody = File.ReadAllBytes("Issue120.txt"); TwitterUserCollection results = SerializationHelper <TwitterUserCollection> .Deserialize(responseBody, DeserializeWrapper); Assert.IsNotNull(results); Assert.IsNotEmpty(results); }
public static void Search() { OAuthTokens tokens = Configuration.GetTokens(); TwitterUserCollection results = TwitterUser.Search(tokens, "twit_er_izer").ResponseObject; Assert.IsNotNull(results); Assert.IsNotEmpty(results); }
/// <summary> /// This method is copied out of the TwitterUserCollection class. /// </summary> /// <param name="value"></param> /// <returns></returns> internal static TwitterUserCollection DeserializeWrapper(JObject value) { if (value == null || value.SelectToken("users") == null) { return(null); } TwitterUserCollection result = JsonConvert.DeserializeObject <TwitterUserCollection>(value.SelectToken("users").ToString()); //result.NextCursor = value.SelectToken("next_cursor").Value<long>(); //result.PreviousCursor = value.SelectToken("previous_cursor").Value<long>(); return(result); }
public void Issue120Test() { String responseBody; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Twitterizer2.MSTestCases.Issue120.txt")) using (var streamReader = new StreamReader(stream)) { responseBody = streamReader.ReadToEnd(); } TwitterUserCollection results = SerializationHelper <TwitterUserCollection> .Deserialize(responseBody, DeserializeWrapper); Assert.IsNotNull(results); Assert.AreNotEqual(0, results.Count); }
private void frmSelectFollowers_Load(object sender, EventArgs e) { foreach (var item in Users) { if (string.IsNullOrWhiteSpace(item)) { continue; } TwitterUserCollection allUser = Classes.TwitterHelper.GetFollowers(item); foreach (var user in allUser) { AddUser(item + ":" + user.ScreenName); } } }
private List <TwitterUserInfo> MapUsers(TwitterUserCollection twitterUserCollection) { if (twitterUserCollection == null) { return(null); } List <TwitterUserInfo> twitterUsers = new List <TwitterUserInfo>(); foreach (TwitterUser twitterUser in twitterUserCollection) { TwitterUserInfo userInfo = MapUser(twitterUser); twitterUsers.Add(userInfo); } return(twitterUsers); }
private List<TwitterUserInfo> MapUsers(TwitterUserCollection twitterUserCollection) { if (twitterUserCollection == null) return null; List<TwitterUserInfo> twitterUsers = new List<TwitterUserInfo>(); foreach (TwitterUser twitterUser in twitterUserCollection) { TwitterUserInfo userInfo = MapUser(twitterUser); twitterUsers.Add(userInfo); } return twitterUsers; }
public static TwitterUserCollection GetFollowers(string screenName) { #region Check that is Titter Follower are Loaded before string AppPath = new FileInfo(Application.ExecutablePath).DirectoryName; string tempFDirectory = Path.Combine(AppPath, string.Format("{0}/tmp/{1}.tmp", AppPath, screenName)); if (File.Exists(tempFDirectory)) { FileInfo F = new FileInfo(tempFDirectory); if (F.CreationTime.Subtract(DateTime.Now).Hours < 100) { StreamReader R = new StreamReader(F.Open(FileMode.Open)); var FileContent = R.ReadToEnd(); R.Close(); return(JsonConvert.DeserializeObject <TwitterUserCollection>(FileContent)); } } #endregion TwitterUserCollection twitterUser = new TwitterUserCollection(); long Curssor = -1; while (true) { if (Curssor == 0) { break; } var folo = TwitterFriendship.Followers(GetUserOAuthTokens(screenName), new FollowersOptions() { Cursor = Curssor }); var xO = JsonConvert.DeserializeObject <TwitterFollowersPage>(folo.Content); if (xO.users == null) { return(twitterUser); } foreach (var item in xO.users) { twitterUser.Add(new TwitterUser { Id = item.id, ScreenName = item.screen_name, Name = item.name, Description = item.description, ProfileImageLocation = item.profile_image_url }); } Curssor = xO.next_cursor; } #region Save File For Later Use var wFileContent = JsonConvert.SerializeObject(twitterUser); if (!Directory.Exists(String.Format("{0}/tmp", AppPath))) { Directory.CreateDirectory(String.Format("{0}/tmp", AppPath)); } if (File.Exists(tempFDirectory)) { File.Delete(tempFDirectory); } StreamWriter w = new StreamWriter(tempFDirectory); w.Write(wFileContent); w.Close(); #endregion return(twitterUser); }