代码:403消息:权限被拒绝谷歌钱包网站Api



我目前正在按照本指南为谷歌钱包创建卡片: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中,"消息":"权限被拒绝&";,"错误":[{"消息":"权限被拒绝&";,"域":"walletobjects";,"原因":"permissionDenied";}]}}

您的代码和请求似乎运行良好。

如果你的请求格式不正确,你会收到一个400错误的请求。

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

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

object_response = http_client.get(OBJECT_URL + OBJECT_ID)

确保字符串正确插入(可能缺少"/"(

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