赞
踩
突然发现苹果api 接口报错,提示如下
- {
- "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"
- }]
- }
然后去官方网址查看了下,原来是过期时间最多不能超过20分钟
也就是jwt 过期时间最多为20分钟
- def __make_jwt_headers(self):
- data = {
- "iss": self.issuer_id,
- "exp": datetime.datetime.utcnow() + datetime.timedelta(seconds=20*60),
- "aud": self.JWT_AUD
- }
- jwt_headers = {
- "alg": self.JWT_ALG,
- "kid": self.private_key_id,
- "typ": "JWT"
- }
- jwt_encoded = jwt.encode(data, self.p8_private_key, algorithm=self.JWT_ALG, headers=jwt_headers)
- headers = {
- 'Authorization': 'Bearer %s' % jwt_encoded
- }
- self.headers = headers

根据 Apple 文档,会话最长持续时间为 20 分钟
https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。