sirkris / Reddit.NET

A Reddit API library for .NET Standard with OAuth support. Written in C#.
MIT License
508 stars 78 forks source link

How to Post to User Profile? #146

Closed RehanSaeed closed 2 years ago

RehanSaeed commented 2 years ago

I'd like to create link posts in my user profile under: https://www.reddit.com/user/muhammadrehansaeed. Is this possible? If so, how?

sirkris commented 2 years ago

Yes this can be accomplished by loading the profile into a Subreddit object with "u_" followed by the username of the profile you want to post to (anything other than your own should throw an exception).

For example:

var profileLinkPost = reddit.Subreddit("u_KrisCraig").LinkPost("https://xkcd.com/308/").Submit()

If you want to dynamically post to the profile of whoever the active user is, then you can do this:

var profileLinkPost = reddit.Subreddit($"u_{reddit.Account.Me.Name}").LinkPost("https://xkcd.com/308/").Submit();

sirkris commented 2 years ago

Updated docs.