我正在尝试从谷歌业务 api 检索数据,我已经设置了一个服务帐户并编写了成功生成不记名授权令牌的代码。然后,我通过获取请求将其作为标头传递,但收到此响应:{'error': {'code': 404, 'message': 'Requested entity was not found.', 'status': 'NOT_FOUND '}}
使用邮递员并发送 oauth 请求会返回所需的信息,但由于这是为自动无人值守运行设置的,因此我想探索服务帐户方法。Myscript 在这里:
'''
import jwt
import requests
import time
import json
iat = time.time()
exp = iat + 3600
payload = {'iss': 'xxxxx.iam.gserviceaccount.com',
'sub': 'xxxxx.iam.gserviceaccount.com',
'aud': 'https://mybusiness.googleapis.com/',
'iat': iat,
'exp': exp}
additional_headers = {'kid': 'xxxxxx'}
signed_jwt = jwt.encode(payload, "-----BEGIN PRIVATE KEY-----xxxxxxx-----END PRIVATE KEY-----\n", headers=additional_headers,
algorithm='RS256')
print(signed_jwt.decode())
response = requests.get('https://mybusiness.googleapis.com/v4/accounts/xxxxxx/locations', headers = {'Authorization':'Bearer '+signed_jwt.decode()})
response = response.json()
print(response)
'''
任何帮助将不胜感激