Код: Выделить всё
import jwt
import requests
import time
import json
KEY_ID = "XXXXXXXXX"
ISSUER_ID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# EXPIRATION_TIME = int(round(time.time() + (20.0 * 60.0))) # 20 minutes timestamp
PATH_TO_KEY = '/Users/164187.victor/Documents/Credentials/App_Store_Connect_RR/AuthKey_XXXXXXXXX.p8'
# pseudo, removed secret info
# read the file, currently binary but have tried string too
with open(PATH_TO_KEY, 'r+b') as keyfile:
secret = keyfile.read()
expir = round(time.time() + 20 * 60)
# sign the token with the iss, time, key, and kid with the correct alg
token = jwt.encode({'iss': ISSUER_ID,
'exp': expir,
'aud': 'appstoreconnect-v1'},
secret, algorithm='ES256',
headers={'alg': 'ES256', 'kid': KEY_ID, 'typ': 'JWT'})
# decode the bytes and create the get request header
headers = {'Authorization': f'Bearer {token}'}
params = {'filter[reportSubType]': 'SUMMARY', 'filter[reportType]': 'SALES', 'filter[frequency]':'DAILY', 'filter[vendorNumber]': 'XXXXXXXX'}
# send the get request
r = requests.get('https://api.appstoreconnect.apple.com/v1/salesReports',
headers=headers, params=params)
# Write the response in a pretty printed JSON file
with open('output.json', 'w') as out:
out.write(json.dumps(r.json(), indent=4))
Код: Выделить всё
{
"errors": [
{
"status": "401",
"code": "NOT_AUTHORIZED",
"title": "Authentication credentials are missing or invalid.",
"detail": "Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens"
}
]
}
- проверяю свой токен в jwt.io, и он там работает нормально.
- использует уровень доступа администратора для привилегий ключа
- при попытке удалить свойства 'alg' в заголовках появляется сообщение, в котором говорится, что это решит проблему, но у меня это не работает
Подробнее здесь: https://stackoverflow.com/questions/703 ... api-python