예제 #1
0
 /// <summary>
 ///     Default overload, takes subreddit as All
 /// </summary>
 public PostBuilder()
 {
     SubredditName = "r/All";
     _subreddit    = Subreddit.GetRSlashAll(_reddit);
 }
예제 #2
0
        static void Main(string[] args)
        {
            Reddit reddit        = null;
            var    authenticated = false;

            while (!authenticated)
            {
                Console.Write("OAuth? (y/n) [n]: ");
                var oaChoice = Console.ReadLine();
                if (!string.IsNullOrEmpty(oaChoice) && oaChoice.ToLower()[0] == 'y')
                {
                    Console.Write("OAuth token: ");
                    var token = Console.ReadLine();
                    reddit = new Reddit(token);
                    reddit.InitOrUpdateUser();
                    authenticated = reddit.User != null;
                    if (!authenticated)
                    {
                        Console.WriteLine("Invalid token");
                    }
                }
                else
                {
                    Console.Write("Username: "******"Password: "******"Logging in...");
                        reddit        = new Reddit(username, password);
                        authenticated = reddit.User != null;
                    }
                    catch (AuthenticationException)
                    {
                        Console.WriteLine("Incorrect login.");
                        authenticated = false;
                    }
                }
            }
            Console.Write("Create post? (y/n) [n]: ");
            var choice = Console.ReadLine();

            if (!string.IsNullOrEmpty(choice) && choice.ToLower()[0] == 'y')
            {
                Console.Write("Type a subreddit name: ");
                var subname = Console.ReadLine();
                var sub     = reddit.GetSubreddit(subname);
                Console.WriteLine("Making test post");
                var post = sub.SubmitTextPost("RedditSharp test", "This is a test post sent from RedditSharp");
                Console.WriteLine("Submitted: {0}", post.Url);
            }
            else
            {
                var subreddit = Subreddit.GetRSlashAll(reddit);
                foreach (var post in subreddit.Posts.Take(10))
                {
                    Console.WriteLine("\"{0}\" by {1}", post.Title, post.Author);
                }
            }
            Console.ReadKey(true);
        }