Search code examples
c#reddit

I'm getting a 404 when trying to set the flair on a post with the Reddit API and RedditSharp wrapper


A bot I created submitted this post to /r/GamingNewsTest. I'm using the RedditSharp wrapper and when I try to call `SetFlair', a 404 exception occurs.

Here's the code I'm currently testing:

subreddit.SubmitPost(redditPost.Title, redditPost.URL, "", "", true).SetFlair("Hearthstone", "");

I checked the parameters the wrapper is sending to the reddit API:

  • api_type : json
  • css_class :
  • link : t3_4e44j3
  • name: GamingNewsBot
  • text: Hearthstone
  • uh / X-Modhash header : No idea. The wrapper handles this internally. Not sure how to grab it without stepping into the assembly.

I'm passing nothing to css_class because there's no associated class at the moment. I can set it manually without one. Do I need to pass something to it? Any other ideas why this might be occurring?


Solution

  • The reason for this is bug in RedditSharp. When you do this:

    var post = subreddit.SubmitPost(title, url, "", "", true);
    

    returned post has SubredditName property set to null. When you then do

    post.SetFlair("Hearthstone", "");
    

    It posts correct data but to wrong url: because SubredditName is null, it posts data to /r//api/flair, hence 404 error.

    Temporary fix would be to set this property before setting flair:

    post.SubredditName = subreddit.Name;
    post.SetFlair("Hearthstone", "");
    

    In long term you have to contact with developer of this library and ask him to fix this bug.