Skip to content

Instantly share code, notes, and snippets.

@chespinoza
Last active April 24, 2020 14:52
Show Gist options
  • Save chespinoza/0aa3d0e0f1ee8cfb1fce04fc825a47cf to your computer and use it in GitHub Desktop.
Save chespinoza/0aa3d0e0f1ee8cfb1fce04fc825a47cf to your computer and use it in GitHub Desktop.
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