예제 #1
0
		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);
				}
			}
		}
예제 #2
0
        static async Task CreateFriendshipAsync(TwitterContext twitterCtx)
        {
            var user = await twitterCtx.CreateFriendshipAsync("JoeMayo", true);

            if (user != null && user.Status != null)
                Console.WriteLine(
                    "User Name: {0}, Status: {1}",
                    user.Name,
                    user.Status.Text);
        }