private static void FollowOnFacebook(Profile profile) { if (!string.IsNullOrWhiteSpace(profile.Facebook)) { string screenName = ""; try { bool result = false; // make the call Console.WriteLine("Attempting to follow this {0} on Facebook", profile.Facebook); var url = new Uri(profile.Facebook); if (url.Segments != null && url.Segments.Length > 0) screenName = url.Segments[url.Segments.Length - 1].Trim(); if (!string.IsNullOrEmpty(screenName)) { // lookup by screenname // if successful, set result = true } else { var queryDict = HttpUtility.ParseQueryString(url.Query); string id = queryDict["id"]; if (!string.IsNullOrEmpty(id)) { // lookup by id // if successful, set result = true } } if (result) facebookCount++; } catch (Exception exc) { Console.WriteLine("***** ERROR *****"); Console.WriteLine(exc.Message); } } }
private static async void FollowOnTwitter(TwitterContext twitterContext, Profile profile) { if (!string.IsNullOrWhiteSpace(profile.Twitter)) { try { string screenName = ""; if (!profile.Twitter.StartsWith("http")) profile.Twitter = "http://" + profile.Twitter; profile.Twitter = profile.Twitter.Replace("#!/", ""); Console.WriteLine("Attempting to follow {0} on Twitter", profile.Twitter); var url = new Uri(profile.Twitter); if (url.Segments != null && url.Segments.Length > 0) screenName = url.Segments[url.Segments.Length - 1].Trim(); if (!string.IsNullOrEmpty(screenName)) { Console.WriteLine("Found screen name {0} generated from {1}", screenName, profile.Twitter); // ensure we aren't already following them if (currentTwitterFriends.IndexOf(screenName) == -1) { var user = await twitterContext.CreateFriendshipAsync(screenName, false); if (user != null && user.Status != null) { // if successful, increment count Console.WriteLine("User Name: {0}, Status: {1}", user.Name, user.Status); Console.WriteLine("Successfully followed {0} - {1} [{2}]", screenName, profile.FullName, profile.Id); twitterCount++; } else { Console.WriteLine("NULL response"); } } else { Console.Write("Already following {0}. Skipping.", screenName); } } } catch (Exception exc) { Console.WriteLine("***** ERROR *****"); Console.WriteLine(exc.Message); } } }