[英]Google my business service account - Requested entity not found using python requests
我正在尝试从 google business api 检索数据,我已经设置了一个服务帐户并编写了成功生成不记名授权令牌的代码。 然后我通过 get 请求将其作为标头传递,但我收到此响应:{'error': {'code': 404, 'message': 'Requested entity was not found.', 'status': 'NOT_FOUND '}}
使用邮递员并发送 oauth 请求会返回所需的信息,但由于这是为自动无人值守运行设置的,我想探索服务帐户方法。 我的脚本在这里:
'''
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)
'''
任何帮助将不胜感激
在 2020 年,仍然无法使用服务帐户从 GMB API 检索数据(这太糟糕了!)。
原因如下: https : //support.google.com/business/thread/1856166?msgid=1856214
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.