【问题标题】:Code: 403 Message:Permission denied Google wallet web Api代码:403 消息:权限被拒绝 Google 钱包网络 API
【发布时间】: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": "权限被拒绝。", “域”:“钱包对象”, “原因”:“权限被拒绝” } ] } }

感谢您提前回答!

【问题讨论】:

    标签: python actions-on-google


    【解决方案1】:

    您的代码和请求似乎工作正常。

    如果您的请求格式不正确,您将收到 400 - 错误请求。

    您确定您的密钥(用于授权)(仍然)有效吗?也许它过期了?

    另一个可能的错误可能在这里:

    object_response = http_client.get(OBJECT_URL + OBJECT_ID)
    

    确保正确连接该字符串(可能缺少“/”)

    无论如何,我无法发现任何其他错误(但当然,我不知道您在这种情况下使用的模块)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-31
      • 2022-08-03
      • 1970-01-01
      • 2015-07-03
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 2017-04-10
      相关资源
      最近更新 更多