Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I change the user behind the VotableThing instance? #236

Closed
VictorioBerra opened this issue Feb 2, 2021 · 6 comments
Closed

Can I change the user behind the VotableThing instance? #236

VictorioBerra opened this issue Feb 2, 2021 · 6 comments

Comments

@VictorioBerra
Copy link

Imagine I have two logins:

var importReddit = new Reddit();
importReddit.LogIn(TargetUsername, TargetPassword);

var exportReddit = new Reddit();
exportReddit.LogIn(DestUsername, DestPassword);

var savedThingies = importAccount.GetSaved();

How can I then transfer the saved things to the second account?

Ideally, I need to be able to .SetUser(User) and then loop and call Save. IE:

var savedThingies = importAccount.GetSaved();
foreach (var savedPost in savedThingies)
{
    savedPost.SetReddit(exportReddit); // or SetUser
    savedPost.Save();
}

I was thinking there had to be another way. Can I somehow get the URI from savedPost, load up a new VotableItem or something and then save?

@CrustyJew
Copy link
Owner

CrustyJew commented Feb 3, 2021

I think you'd want to just use your exportReddit to save the post again directly via the URL/thingid/however the save item portion is implemented. I haven't used it to be perfectly honest. Then if you want to remove the saved thing from the first user, use the importReddit instance to do that.

@VictorioBerra
Copy link
Author

Gotcha, I will look into that now. I need to find the member of exportReddit that takes a URL/thingid.

@CrustyJew
Copy link
Owner

It looks like RedditUser doesn't implement anything to actually save posts. It may need a pull request to add that functionality, i'm only seeing a way to retrieve them.

@VictorioBerra
Copy link
Author

VictorioBerra commented Feb 3, 2021 via email

@CrustyJew
Copy link
Owner

ohhh yeah that might work. So in that case you'd want to do a new "get post" on your import instance and then save the post. Alternatively I think you can actually just call the LogIn method again on your instance of Reddit to change the user like you were originally wanting to do now that I think about it more >.<

@VictorioBerra
Copy link
Author

I just tested this with the following code and it seems to be working.

var savedThingies = importAccount.GetSaved().ToList();
// Change login instance!
importReddit.LogIn(DestUsername, DestPassword);
foreach (var savedPost in savedThingies)
{
    Console.WriteLine("Saving thing " + savedPost.FullName + " " + savedPost.Id + " " + savedPost.Shortlink);
    try {
        savedPost.Save();
        Console.WriteLine("Success.");
    }
    catch(Exception ex)
    {
        Console.WriteLine("Failed!");
        Console.WriteLine(ex);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants