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

Issue with Following #11

Open
zykrah opened this issue Jun 21, 2020 · 4 comments
Open

Issue with Following #11

zykrah opened this issue Jun 21, 2020 · 4 comments

Comments

@zykrah
Copy link

zykrah commented Jun 21, 2020

from instpector import Instpector, endpoints

class InstaBot():
    def __init__(self, username, password):
        self.username = username
        self.password = password

        self.api = Instpector()
        self.profile_endpoint = endpoints.factory.create("profile", self.api)

    def login(self, two_factor_code=None):
        api = self.api
        api.login(self.username, self.password, two_factor_code)
    
    def logout(self):
        api = self.api
        api.logout()

    def follow(self, user):
        prof_end = self.profile_endpoint
        if isinstance(user, str):
            profile = prof_end.of_user(user)
        else:
            profile = prof_end.of_user(user.username)
        return prof_end.follow(profile)
        print(f"Followed {profile.username}")

    def unfollow(self, user):
        prof_end = self.profile_endpoint
        if isinstance(user, str):
            profile = prof_end.of_user(user)
        else:
            profile = prof_end.of_user(user.username)
        return prof_end.unfollow(profile)
        print(f"Unfollowed {profile.username}")

Above is my code

bot = InstaBot("username", "password")
bot.login()
print(bot.follow("therock")) # Doesnt work, returns/prints False
bot.logout()

Above is what i want to work, but cant get to work

bot = InstaBot("username", "password")
bot.login()
profile = endpoints.factory.create("profile", bot.api)
prof = profile.of_user("therock")
print(profile.follow(prof)) # Does work, returns/prints True
bot.logout()

Above is a way around the issue i made, but it is really inconvenient...

Please help!

@zykrah
Copy link
Author

zykrah commented Jun 21, 2020

there is an error in my code with unreachable code. The print() in follow() and unfollow(). But it has no relevancy to the issue, just thought i'd point out that i already fixed that issue.

@zykrah
Copy link
Author

zykrah commented Jun 21, 2020

I can successfully grab a profile using the code using

prof = bot.profile_endpoint.of_user("therock")

however, when i try to follow the profile using

bot.profile_endpoint.follow(prof)

It doesn't work, and returns False (when you print the line above)

@zykrah
Copy link
Author

zykrah commented Jun 21, 2020

One more thing. I have tested both Followers and Following Endpoints, and have no issues with either so far.

@zykrah
Copy link
Author

zykrah commented Jun 21, 2020

I seemed to have solve the issue (sorta).

    def profile_endpoint(self):
        return endpoints.factory.create("profile", self.api)

By using the above code, replacing:

self.profile_endpoint = self.endpoints.factory.create("profile", self.api)

and by referring to the endpoint as

bot.profile_endpoint()

Though i dont see why i couldnt use my original code... please correct me if i am wrong!

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

1 participant