uburuntu / rawg

🎮 Async API wrapper for RAWG.io
https://rawg.io
33 stars 2 forks source link

Q: where do i put the api key? #5

Closed FrnandMG closed 2 years ago

FrnandMG commented 3 years ago

Hello, where do i put the api key??

import asyncio

import rawg

async def requests():
    async with rawg.ApiClient() as api_client:
        # Create an instance of the API class
        api = rawg.GamesApi(api_client)

        # Making requests
        coros = [api.games_read(id=name) for name in ['grand-theft-auto-v', 'minecraft']]

        # Waiting for requests
        for coro in asyncio.as_completed(coros):
            game: rawg.GameSingle = await coro
            print('        Name |', game.name)
            print('    Released |', game.released)
            print('      Rating |', game.rating)
            print('Achievements |', game.achievements_count)
            print('     Website |', game.website)
            print('  Metacritic |', game.metacritic)
            print('——————————————————————————————————————————————')

if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(requests())
AndrejGorodnij commented 2 years ago

@FrnandMG

You need to use parameter "configuration" of ApiClient() , what is rawg.Configuration() object. This object contain api_key, username, password and other parameters.

Something like this:


config = rawg.Configuration(api_key=client_api_key)

async def requests():

   async with rawg.ApiClient(configuration=config) as api_client:
FrnandMG commented 2 years ago

@AndrejGorodnij thank you.

egirlcatnip commented 2 years ago

Hi there, I am a newbie and still haven't figured it out.. I've tried defining client_api_key as a string containing the api key, but I am doing something wrong.. Help would be appreciated. :>

egirlcatnip commented 2 years ago

image This is how thecoros code looks, I think I can figure out the rest, but I need the help with the api key

uburuntu commented 2 years ago

Hello @EmilyisWIP @FrnandMG 👋🏻 I updated the package to v1.2.0 -- now it works well with api keys, provide them this way: rawg.Configuration(api_key={'key': 'YOUR_API_KEY'})

Full example in README and here: https://github.com/uburuntu/rawg/blob/master/examples/games_api.py

Update the package: pip install -U rawg