当前位置: 首页>>代码示例>>C#>>正文


C# Reddit.InitOrUpdateUser方法代码示例

本文整理汇总了C#中RedditSharp.Reddit.InitOrUpdateUser方法的典型用法代码示例。如果您正苦于以下问题:C# Reddit.InitOrUpdateUser方法的具体用法?C# Reddit.InitOrUpdateUser怎么用?C# Reddit.InitOrUpdateUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RedditSharp.Reddit的用法示例。


在下文中一共展示了Reddit.InitOrUpdateUser方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

 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: ");
             var username = Console.ReadLine();
             Console.Write("Password: ");
             var password = ReadPassword();
             try
             {
                 Console.WriteLine("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
     {
         Console.Write("Type a subreddit name: ");
         var subname = Console.ReadLine();
         var sub = reddit.GetSubreddit(subname);
         foreach (var post in sub.GetTop(FromTime.Week).Take(10))
             Console.WriteLine("\"{0}\" by {1}", post.Title, post.Author);
     }
     Console.ReadKey(true);
 }
开发者ID:keneo,项目名称:RedditSharp,代码行数:58,代码来源:Program.cs

示例2: Main

 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: ");
             var username = Console.ReadLine();
             Console.Write("Password: ");
             var password = ReadPassword();
             try
             {
                 Console.WriteLine("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
     {
         Console.Write("Type a subreddit name: ");
         var subname = Console.ReadLine();
         var sub = reddit.GetSubreddit(subname);
         foreach (var post in sub.GetTop(FromTime.Week).Take(10))
             Console.WriteLine("\"{0}\" by {1}", post.Title, post.Author);
     }*/
     Comment comment = (Comment)reddit.GetThingByFullname("t1_ciif2g7");
     Post post = (Post)reddit.GetThingByFullname("t3_298g7j");
     PrivateMessage pm = (PrivateMessage)reddit.GetThingByFullname("t4_20oi3a"); // Use your own PM here, as you don't have permission to view this one
     Console.WriteLine(comment.Body);
     Console.WriteLine(post.Title);
     Console.WriteLine(pm.Body);
     Console.WriteLine(post.Comment("test").FullName);
     Console.ReadKey(true);
 }
开发者ID:RobThree,项目名称:RedditSharp,代码行数:65,代码来源:Program.cs


注:本文中的RedditSharp.Reddit.InitOrUpdateUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。