本文整理汇总了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);
}
示例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);
}