niuware / instpector

A simple Instagram's web API library
MIT License
17 stars 5 forks source link

Issue with Following #11

Open zykrah opened 4 years ago

zykrah commented 4 years ago
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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

zykrah commented 4 years ago

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!