/// <summary> /// Get the Twitter response object for the friends /// </summary> /// <returns></returns> private TwitterResponse <TwitterUserCollection> GetTwitterFriends() { TwitterResponse <TwitterUserCollection> twitterResponse = new TwitterResponse <TwitterUserCollection>(); if (Page.Cache[string.Format("TwitterFriends-{0}", this.ScreenName)] == null) { //create a authorization token of the user OAuthTokens tokens = new OAuthTokens(); tokens.ConsumerKey = this.ConsumerKey; tokens.ConsumerSecret = this.ConsumerSecret; tokens.AccessToken = this.AccessToken; tokens.AccessTokenSecret = this.AccessTokenSecret; //Set the query options FriendsOptions Friendoptions = new FriendsOptions(); Friendoptions.ScreenName = this.ScreenName; Friendoptions.Cursor = -1; //get the Following Object from the Twitter twitterResponse = TwitterFriendship.Friends(tokens, Friendoptions); HttpContext.Current.Cache.Insert(string.Format("TwitterFriends-{0}", this.ScreenName), twitterResponse, null, DateTime.Now.AddMinutes(Common.CACHEDURATION), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null); } else { twitterResponse = Page.Cache[string.Format("TwitterFriends-{0}", this.ScreenName)] as TwitterResponse <TwitterUserCollection>; } return(twitterResponse); }
public static void ShowCreateAndDelete() { OAuthTokens tokens = Configuration.GetTokens(); // See if the friendship exists (it should not) TwitterRelationship friendship = TwitterFriendship.Show(tokens, "rickydev").ResponseObject; // If it exists, delete it. if (friendship.Target.Following) { DeleteFriendship(tokens, friendship); } // Create the friendship TwitterUser followedUser = TwitterFriendship.Create(tokens, "rickydev").ResponseObject; Assert.IsNotNull(followedUser); // Get the friendship details (maybe again) friendship = TwitterFriendship.Show(tokens, "rickydev").ResponseObject; Assert.IsNotNull(friendship); Assert.IsNotNull(friendship.Target); // Delete the friendship (maybe again) DeleteFriendship(tokens, friendship); }
/// <summary> /// Recibe una lista de usuarios y si estos no me siguen deja de seguirlos. /// </summary> /// <param name="listUsers"></param> /// <returns>JarvisResponse</returns> public static JarvisResponse unfollowBadUsers(List <TwitterUser> listUsers) { int counter = 0; JarvisResponse jResponse = new JarvisResponse(); StringBuilder aux = new StringBuilder(); foreach (var item in listUsers) { counter++; // Para manejar el Rate limit de Twitter usamos contador. // 15 Requests cada 15 Minutos. if (counter < 50) { TwitterFriendship test = mainService.GetFriendshipInfo(new GetFriendshipInfoOptions { TargetId = item.Id.ToString() }); if (test.Relationship.Target.FollowedBy == true && test.Relationship.Target.Following == false) { jResponse.count++; mainService.UnfollowUser(new UnfollowUserOptions { UserId = item.Id }); aux.AppendLine("@" + item.ScreenName + " - ID: " + item.Id); aux.AppendLine("Relationship state = " + test.Relationship.Target.Following); } } } aux.AppendLine("Cantidad de usuarios seguidos: " + jResponse.count); Jarvis.unfollowCount += jResponse.count; jResponse.message = aux.ToString(); return(jResponse); }
public void FollowersIds() { OAuthTokens tokens = Configuration.GetTokens(); TwitterResponse <UserIdCollection> response = TwitterFriendship.FollowersIds(tokens, new UsersIdsOptions { ScreenName = "twitterapi" }); Assert.IsNotNull(response, "response is null"); Assert.IsTrue(response.Result == RequestResult.Success, response.ErrorMessage ?? response.Result.ToString()); Assert.IsNotNull(response.ResponseObject, response.ErrorMessage ?? response.Result.ToString()); Assert.IsTrue(response.ResponseObject.Count > 0, response.ErrorMessage ?? response.Result.ToString()); decimal firstId = response.ResponseObject[0]; response = TwitterFriendship.FollowersIds(tokens, new UsersIdsOptions { ScreenName = "twitterapi", Cursor = response.ResponseObject.NextCursor }); Assert.IsNotNull(response, "response is null"); Assert.IsTrue(response.Result == RequestResult.Success, response.ErrorMessage ?? response.Result.ToString()); Assert.IsNotNull(response.ResponseObject, response.ErrorMessage ?? response.Result.ToString()); Assert.IsTrue(response.ResponseObject.Count > 0, response.ErrorMessage ?? response.Result.ToString()); Assert.AreNotEqual(response.ResponseObject[0], firstId, response.ErrorMessage ?? response.Result.ToString()); }
public static void FollowersIds() { OAuthTokens tokens = Configuration.GetTokens(); TwitterResponse <UserIdCollection> response = TwitterFriendship.FollowersIds(tokens, new UsersIdsOptions { ScreenName = "twitterapi" }); Assert.IsNotNull(response); Assert.That(response.Result == RequestResult.Success); Assert.IsNotNull(response.ResponseObject); Assert.That(response.ResponseObject.Count > 0); decimal firstId = response.ResponseObject[0]; response = TwitterFriendship.FollowersIds(tokens, new UsersIdsOptions { ScreenName = "twitterapi", Cursor = response.ResponseObject.NextCursor }); Assert.IsNotNull(response); Assert.That(response.Result == RequestResult.Success); Assert.IsNotNull(response.ResponseObject); Assert.That(response.ResponseObject.Count > 0); Assert.AreNotEqual(response.ResponseObject[0], firstId); }
/// <summary> /// Check if the user is fozlowing or not. /// </summary> /// <returns>Boolean</returns> public static bool checkFriendship(long id) { TwitterFriendship test = mainService.GetFriendshipInfo(new GetFriendshipInfoOptions { TargetId = id.ToString() }); return(test.Relationship.Target.Following); }
public static void ReradusTest() { //OAuthTokens tokens = Configuration.GetTokens(); FollowersOptions options = new FollowersOptions(); //options.ScreenName = _Screenname; options.UserId = 189996115; var followers = TwitterFriendship.Followers(options); }
public static void GetFriendIds() { OAuthTokens tokens = Configuration.GetTokens(); var response = TwitterFriendship.FriendsIds(tokens, new UsersIdsOptions()); Assert.IsNotNull(response); Assert.That(response.Result == RequestResult.Success); Assert.IsNotNull(response.ResponseObject); Assert.IsNotEmpty(response.ResponseObject); }
public void GetFriendIds() { OAuthTokens tokens = Configuration.GetTokens(); var response = TwitterFriendship.FriendsIds(tokens, new UsersIdsOptions()); Assert.IsNotNull(response, "response is null"); Assert.IsTrue(response.Result == RequestResult.Success, response.ErrorMessage); Assert.IsNotNull(response.ResponseObject, response.ErrorMessage); Assert.AreNotEqual(0, response.ResponseObject.Count, response.ErrorMessage); }
public void ReradusTest() { //OAuthTokens tokens = Configuration.GetTokens(); FollowersOptions options = new FollowersOptions(); //options.ScreenName = _Screenname; options.UserId = 189996115; var followers = TwitterFriendship.Followers(options); Assert.IsNotNull(followers.ResponseObject, followers.ErrorMessage); }
public static JarvisResponse getRelationInformation(long userId) { JarvisResponse jResponse = new JarvisResponse(); StringBuilder sBuilder = new StringBuilder(); TwitterFriendship rs = mainService.GetFriendshipInfo(new GetFriendshipInfoOptions { TargetId = userId.ToString() }); sBuilder.AppendLine("FollowedBy: " + rs.Relationship.Target.FollowedBy.ToString()); sBuilder.AppendLine("Following: " + rs.Relationship.Target.Following.ToString()); jResponse.message = sBuilder.ToString(); return(jResponse); }
void ReceiveFriendshipInfo(TwitterFriendship friendship, TwitterResponse response) { FriendshipRetrieved = true; if (response.StatusCode != HttpStatusCode.OK) { MessageService.ShowWarning(Resources.CouldntGetRelationship); return; } Followed = friendship.Relationship.Source.Following; FollowsMe = friendship.Relationship.Source.FollowedBy; UpdateRelationshipText(); followUser.RaiseCanExecuteChanged(); unfollowUser.RaiseCanExecuteChanged(); }
private void button1_Click(object sender, EventArgs e) { try { showUserResponse = TwitterUser.Show(oa, scr); user = showUserResponse.ResponseObject; if (user.IsFollowing == true) { TwitterResponse <TwitterUser> follow = TwitterFriendship.Delete(oa, user.ScreenName); update(); } else if (user.IsFollowing == false) { TwitterResponse <TwitterUser> follow = TwitterFriendship.Create(oa, user.ScreenName); update(); } } catch { MessageBox.Show("Some error happened"); } }
public static CommandResult GetFollowerList(string[] screennames) { if (!IsInitiated) { return(CommandResult.NotInitiated); } foreach (var screenname in screennames) { var user = CheckUserExistsInDb(screenname); if (user == null) { Form.AppendLineToOutput("Failed. @" + screenname + " not found in Db", Color.Maroon); continue; } DateTime WhenSaved = DateTime.Today; int FollowersSaved = 0; int NotSaved = 0; long NextCursor = -1; #region log to file for resuming var logFilePath = @"./" + screenname + "-GetFollowerList.resume"; if (File.Exists(logFilePath)) { var NextCursorAsText = File.ReadAllText(logFilePath); long.TryParse(NextCursorAsText, out NextCursor); } #endregion do { var db = new TwitterContext(); db.Configuration.AutoDetectChangesEnabled = false; TwitterResponse <UserIdCollection> Response = TwitterFriendship.FollowersIds(Tokens, new UsersIdsOptions { ScreenName = screenname, Cursor = NextCursor }); if (Response.Result == RequestResult.Success && Response.ResponseObject != null) { File.WriteAllText(logFilePath, NextCursor.ToString()); //to note where to resume from try { var followersID = Response.ResponseObject; NextCursor = followersID.NextCursor; foreach (var id in followersID.ToList()) { try { db.Friendships.Add(new Friendship { UserId = user.Id, FollowerId = id, WhenSaved = WhenSaved }); FollowersSaved++; db.SaveChanges(); } catch (Exception ex) { Form.AppendLineToOutput(string.Format("Unexpected error with user {0} and follower {1} : {2}", user.ScreenName, id, ex.Message), Color.Maroon); db = new TwitterContext(); NotSaved++; } } Form.AppendLineToOutput(string.Format("Saved {0} followers so far; {1} not saved", FollowersSaved, NotSaved), Color.Maroon); } catch (Exception ex) { Form.AppendLineToOutput("Unexpected error: " + ex.Message); } } else if (Response.Result == RequestResult.Unauthorized || Response.Result == RequestResult.FileNotFound) { Form.AppendLineToOutput("User " + user.ScreenName + " is now protected or no longer exists.", Color.Maroon); } else if (Response.Result == RequestResult.RateLimited) { WaitForRateLimitReset(Response); Form.AppendLineToOutput("Resuming GetFollowerList command", Color.Maroon); continue; } else //Just in case if the program is unexpectedly failed and closed, record last processed page number { Form.AppendLineToOutput("Error: " + Response.Result, Color.Maroon); //StreamWriter w1 = new StreamWriter("SaveFollowingsList_PageSoFar.txt"); //w1.WriteLine("Record datetime: " + DateTime.Now); //w1.WriteLine("Page number next to be: " + nextCursor); //w1.Close(); //Console.WriteLine("End of Process"); break; } } while (NextCursor > 0); if (File.Exists(logFilePath)) { File.Delete(logFilePath); //remove log file. We're done with this user now. } } //end loop for each screenname return(CommandResult.Success); }
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); }
private void getUserFriends(string username) { getWaitCursor(); //FollowersOptions options = new FollowersOptions(); //TwitterResponse<TwitterUserCollection> followers = TwitterFriendship.Friends(_authToken); TwitterResponse <TwitterUserCollection> friends = TwitterFriendship.Friends(_authToken); if (friends.Result == RequestResult.Success) { try { int friendsNumber = friends.ResponseObject.Count; for (int j = 0; j < friendsNumber; j++) { var result = friends.ResponseObject[j]; if (j == 99) { friends = friends.ResponseObject.NextPage(); friendsNumber = friends.ResponseObject.Count; //MessageBox.Show(friendsNumber.ToString()); j = 0; continue; } ListViewItem friend = new ListViewItem(); //follower.Name = result.ScreenName; friend.Uid = result.Id.ToString(); //MessageBox.Show(friend.Uid.ToString()); // follower.MouseDoubleClick += new MouseButtonEventHandler(ListViewFollower_Selected); StackPanel stack = new StackPanel();; stack.Width = 100; //stack.Orientation = System.Windows.Controls.Orientation.Vertical; Label lbl = new Label(); lbl.Content = result.ScreenName; lbl.Foreground = Brushes.White; lbl.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; BitmapImage avatar = new BitmapImage(); avatar.BeginInit(); // Set properties. avatar.CacheOption = BitmapCacheOption.OnDemand; avatar.CreateOptions = BitmapCreateOptions.IgnoreColorProfile; avatar.UriSource = new Uri(result.ProfileImageLocation); avatar.DecodePixelHeight = 48; avatar.DecodePixelWidth = 48; // End initialization. avatar.EndInit(); Image img = new Image(); img.Source = avatar; img.Width = 48; img.Height = 48; img.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; stack.Children.Add(img); //Console.WriteLine(result.ScreenName + ": img ->" + result.ProfileImageLocation); stack.Children.Add(lbl); friend.Content = stack; listviewFollowers.Items.Add(friend); } //listviewFollowers.scro } catch (TwitterizerException e1) { MessageBox.Show("Erro - " + e1); } } else { MessageBox.Show(friends.ErrorMessage); } //Number of followers added lblFollowers.Content = "Following " + listviewFollowers.Items.Count.ToString(); getDefaultCursor(); }