Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="session"></param>
        /// <param name="post"></param>
        /// <see cref="https://github.com/reddit/reddit/wiki/API"/>
        public static void Submit(Session session, Post post, PostKind kind)
        {
            if (string.IsNullOrEmpty((kind == PostKind.Link ? post.Url : post.SelfText)))
            {
                throw new Exception("No link or self text added to the new post");
            }

            if (string.IsNullOrEmpty(post.SubReddit))
            {
                throw new Exception("No subreddit set");
            }

            if (string.IsNullOrEmpty(post.Title))
            {
                throw new Exception("No title provided");
            }

            var request = new Request
            {
                Url     = "http://www.reddit.com/api/submit",
                Method  = "POST",
                Cookie  = session.Cookie,
                Content = "uh=" + session.ModHash +
                          "&kind=" + (kind == PostKind.Link ? "link" : "self") +
                          "&url=" + (kind == PostKind.Link ? post.Url : post.SelfText) +
                          "&sr=" + post.SubReddit +
                          "&title=" + post.Title +
                          "&r=" + post.SubReddit +
                          "&renderstyle=html"
            };

            var json = string.Empty;

            if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
            {
                throw new Exception(json);
            }

            var o = JObject.Parse(json);

            // Capcha
            // o["jquery"][10][3].ToString()

            // Error Message
            // o["jquery"][12][3].ToString()
        }
        public void Post(PostKind pk, bool resubmit, bool sendReplies, string subreddit, string title, string text = null, string url = null)
        {
            GetAccessToken();

            var values = new Dictionary <string, string>
            {
                { "api_type", "json" },
                { "kind", pk.ToString().ToLower() },
                { "resubmit", resubmit.ToString().ToLower() },
                { "sendreplies", sendReplies.ToString().ToLower() },
                { "sr", subreddit.ToLower() },
                { "title", title }
            };

            switch (pk)
            {
            case PostKind.Self:
                if (text == null)
                {
                    throw new Exception();
                }

                values.Add("text", text);
                break;

            default:
                if (url == null)
                {
                    throw new Exception();
                }

                values.Add("url", url);
                break;
            }

            var response       = client.PostAsync(SUBMIT_URL, new FormUrlEncodedContent(values)).Result;
            var responseString = response.Content.ReadAsStringAsync().Result;

            Console.WriteLine(responseString);
        }
Beispiel #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="session"></param>
        /// <param name="post"></param>
        /// <see cref="https://github.com/reddit/reddit/wiki/API"/>
        public static void Submit(Session session, Post post, PostKind kind)
        {
            if (string.IsNullOrEmpty((kind == PostKind.Link ? post.Url : post.SelfText)))
                throw new Exception("No link or self text added to the new post");

            if (string.IsNullOrEmpty(post.SubReddit))
                throw new Exception("No subreddit set");

            if (string.IsNullOrEmpty(post.Title))
                throw new Exception("No title provided");

            var request = new Request
            {
                Url = "http://www.reddit.com/api/submit",
                Method = "POST",
                Cookie = session.Cookie,
                Content = "uh=" + session.ModHash +
                          "&kind=" + (kind == PostKind.Link ? "link" : "self") +
                          "&url=" + (kind == PostKind.Link ? post.Url : post.SelfText) +
                          "&sr=" + post.SubReddit +
                          "&title=" + post.Title +
                          "&r=" + post.SubReddit +
                          "&renderstyle=html"
            };

            var json = string.Empty;
            if (request.Execute(out json) != System.Net.HttpStatusCode.OK)
                throw new Exception(json);

            var o = JObject.Parse(json);

            // Capcha
            // o["jquery"][10][3].ToString()

            // Error Message
            // o["jquery"][12][3].ToString()
        }