【发布时间】:2022-11-08 21:21:35
【问题描述】:
我目前正在按照本指南为谷歌钱包创建卡片:https://developers.google.com/wallet/retail/loyalty-cards/web
我之前完成了所有步骤,现在处于“创建通道对象”步骤。
这是我当前的代码:
KEY_FILE_PATH = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS",
"/Users/me/key.json")
ISSUER_ID = os.environ.get("WALLET_ISSUER_ID", "MY_Issuer_Id")
CLASS_ID = os.environ.get("WALLET_CLASS_ID", "My_Wallet_class_id")
USER_ID = os.environ.get("WALLET_USER_ID", "my@email.com")
OBJECT_ID = "%s.%s-%s" % (ISSUER_ID, re.sub(r"[^\w.-]", "_", USER_ID), CLASS_ID)
credentials = service_account.Credentials.from_service_account_file(
KEY_FILE_PATH,
scopes=["https://www.googleapis.com/auth/wallet_object.issuer"])
http_client = AuthorizedSession(credentials)
OBJECT_URL = "https://walletobjects.googleapis.com/walletobjects/v1/loyaltyObject/"
object_payload = {
"id": OBJECT_ID,
"classId": f"{ISSUER_ID}.{CLASS_ID}",
"heroImage": {
"sourceUri": {
"uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
"description": "Test heroImage description"
}
},
"textModulesData": [
{
"header": "Test text module header",
"body": "Test text module body"
}
],
"linksModuleData": {
"uris": [
{
"kind": "walletobjects#uri",
"uri": "http://maps.google.com/",
"description": "Test link module uri description"
},
{
"kind": "walletobjects#uri",
"uri": "tel:6505555555",
"description": "Test link module tel description"
}
]
},
"imageModulesData": [
{
"mainImage": {
"kind": "walletobjects#image",
"sourceUri": {
"kind": "walletobjects#uri",
"uri": "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
"description": "Test image module description"
}
}
}
],
"barcode": {
"kind": "walletobjects#barcode",
"type": "qrCode",
"value": "Test QR Code"
},
"state": "active",
"accountId": "Test account id",
"accountName": "Test account name",
"loyaltyPoints": {
"balance": {
"string": "800"
},
"label": "Points"
},
"locations": [
{
"kind": "walletobjects#latLongPoint",
"latitude": 37.424015499999996,
"longitude": -122.09259560000001
}
]
}
object_response = http_client.get(OBJECT_URL + OBJECT_ID)
if object_response.status_code == 404:
object_response = http_client.post(
OBJECT_URL,
json=object_payload
)
print("object GET or POST response:", object_response.text)
我得到了他的错误:
对象 GET 或 POST 响应:{ “错误”: { “代码”:403, "message": "权限被拒绝。", “错误”:[ { "message": "权限被拒绝。", “域”:“钱包对象”, “原因”:“权限被拒绝” } ] } }
感谢您提前回答!
【问题讨论】: