Last active
April 24, 2020 14:52
-
-
Save chespinoza/0aa3d0e0f1ee8cfb1fce04fc825a47cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import asyncio | |
from authlib.integrations.httpx_client import AsyncOAuth2Client | |
from httpx import BasicAuth | |
AAAPI_TOKEN_URL = os.environ["AAAPI_TOKEN_URL"] | |
AAAPI_BASE_URI = os.environ["AAAPI_BASE_URI"] | |
CLIENT_SECRET = os.environ["CLIENT_SECRET"] | |
CLIENT_ID = os.environ["CLIENT_ID"] | |
REFRESH_TOKEN = os.environ["REFRESH_TOKEN"] | |
async def main(): | |
token = { | |
"token_type": "Bearer", | |
#'access_token': None, | |
"refresh_token": REFRESH_TOKEN, | |
"expires_in": "3600", | |
"expires_at": int(time.time()) + 3600, | |
} | |
client = AsyncOAuth2Client( | |
client_id=CLIENT_ID, | |
client_secret=CLIENT_SECRET, | |
token_endpoint=AAAPI_TOKEN_URL, | |
token=token, | |
token_endpoint_auth_method="client_secret_post", | |
# token_endpoint_auth_method="client_secret_basic", | |
# update_token=update_token, | |
scope="cpc_advertising:campaign_management", | |
) | |
headers = {"Amazon-Advertising-API-ClientId": CLIENT_ID} | |
auth = BasicAuth(username=CLIENT_ID, password=CLIENT_SECRET) | |
response = await client.fetch_token(AAAPI_TOKEN_URL, refresh_token=REFRESH_TOKEN, auth=auth, headers=headers, response_type="code") | |
if __name__=="__main__": | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment