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

Feature/access token magic 2 #19

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Conversation

pekasen
Copy link
Collaborator

@pekasen pekasen commented Feb 5, 2025

Adds an AccessToken class that automatically gets and refreshes the bearer token from the OAuth endpoint.

Tests are updated as well. However, in tests for get_liked_videos and get_user_followers is an assertion error. I suggest retaining the tests as they are and fixing them, when merging with the refactored social graph implementations.

@pekasen pekasen marked this pull request as ready for review February 6, 2025 10:09
@pekasen pekasen added the enhancement New feature or request label Feb 6, 2025
Fix typo in example code for importing the AccessToken.
@tomasruizt
Copy link
Collaborator

I personally think that simple caching with a time expiration does the job:

@ttl_cache(ttl=7200 - 1)  # to be safe
def get_access_token_cached() -> str:
    client_key = os.environ["TIKTOK_CLIENT_KEY"]
    client_secret = os.environ["TIKTOK_CLIENT_SECRET"]
    logger.info("Getting access token...")
    data: dict = get_access_token(
        client_key=client_key, client_secret=client_secret
    )
    return data["access_token"]

but if you like this class-based solution, fine with me :)

@pekasen pekasen mentioned this pull request Feb 6, 2025
@pekasen
Copy link
Collaborator Author

pekasen commented Feb 6, 2025

I personally think that simple caching with a time expiration does the job:

@ttl_cache(ttl=7200 - 1)  # to be safe
def get_access_token_cached() -> str:
    client_key = os.environ["TIKTOK_CLIENT_KEY"]
    client_secret = os.environ["TIKTOK_CLIENT_SECRET"]
    logger.info("Getting access token...")
    data: dict = get_access_token(
        client_key=client_key, client_secret=client_secret
    )
    return data["access_token"]

but if you like this class-based solution, fine with me :)

See your point, there's definitely elegance to it. However, I'd like a solution where the API is in control of the expiration time. I'll check whether I can provide a simpler solution.

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

Successfully merging this pull request may close these issues.

2 participants