subzeroid / aiograpi

🔥 Asynchronous Python library for Instagram Private API 2024
https://hikerapi.com/p/KhMxYMSn
MIT License
112 stars 19 forks source link

[BUG] Example not working #52

Open datacubeR opened 4 months ago

datacubeR commented 4 months ago

Try HikerAPI SaaS with a free trial https://hikerapi.com/p/KhMxYMSn

Describe the bug Running the README example simply just don't work.

To Reproduce

from aiograpi import Client

ACCOUNT_USERNAME = "myuser"
ACCOUNT_PASSWORD = "mypassword"

cl = Client()
await cl.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD)

user_id = await cl.user_id_from_username(ACCOUNT_USERNAME)
medias = await cl.user_medias(user_id, 20)

Traceback

Screenshot from 2024-05-24 16-18-54

Expected behavior A working Script

Screenshots Show above...

Desktop (please complete the following information):

Additional context I'm just getting familiar with the API so a more descriptive error would be very beneficial.

ajkessel commented 2 months ago

You need to do something like this, because async functionality needs to be in an async function:

import asyncio
import aiograpi

async def test():
   ACCOUNT_USERNAME = "myuser"
   ACCOUNT_PASSWORD = "mypassword"
   cl = Client()
   await cl.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD)
   user_id = await cl.user_id_from_username(ACCOUNT_USERNAME)
   medias = await cl.user_medias(user_id, 20)

async def main():
    await test()

if __name__ ==  '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())