在 PHP 上创建通用基类时,Google Wallet API 出现无效参数错误

问题描述 投票:0回答:2

我尝试实现 Google Wallet API 以使用 PHP 创建通用卡通行证,并且我正在使用此处描述的演示代码:https://github.com/google-wallet/rest-samples/blob/main/php/demo_generic .php。当我创建一个仅使用 id 作为类定义的类时(['id' => $issuerId . '.' . $classSuffix]),它可以工作,但是如果我使用下面的类基,我会得到无效参数错误:

    Google\Service\Exception {
      #message: """
        {
    
          "error": {
    
            "code": 400,
    
            "message": "Request contains an invalid argument.",
    
            "errors": [
    
              {
    
                "message": "Request contains an invalid argument.",
    
                "domain": "global",
    
                "reason": "badRequest"
    
              }
    
            ],
    
            "status": "INVALID_ARGUMENT"
    
          }
    
        }
    
        """
      #code: 400
      #file: "../vendor/google/apiclient/src/Http/REST.php"
      #errors: array:1 [
        0 => array:3 [
          "message" => "Request contains an invalid argument."
          "domain" => "global"
          "reason" => "badRequest"
        ]
      ]
    }
  

我的类基定义:

$classDef = [
                'id' => $issuerId .  '.' . self::CLASS_SUFFIX,
                'classTemplateInfo' => [
                    'cardTemplateOverride' => [
                        'cardRowTemplateInfos' => [
                            [
                                'twoItems' => [
                                    'startItem' => [
                                        'firstValue' => [
                                            'fields' => [
                                                [
                                                    'fieldPath' => 'object.textModulesData["points"]'
                                                ]
                                            ]
                                        ]
                                    ],
                                    'endItem' => [
                                        'firstValue' => [
                                            'fields' => [
                                                [
                                                    'fieldPath' => 'object.textModulesData["contacts"]'
                                                ]
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ],
                    'detailsTemplateOverride' => [
                        'detailsItemInfos' => [
                            [
                                'item' => [
                                    'firstValue' => [
                                        'fields' => [
                                            [
                                                'fieldPath' => 'class.imageModulesData["event_banner"]'
                                            ]
                                        ]
                                    ]
                                ]
                            ],
                            [
                                'item' => [
                                    'firstValue' => [
                                        'fields' => [
                                            [
                                                'fieldPath' => 'class.textModulesData["game_overview"]'
                                            ]
                                        ]
                                    ]
                                ]
                            ],
                            [
                                'item' => [
                                    'firstValue' => [
                                        'fields' => [
                                            [
                                                'fieldPath' => 'class.linksModuleData.uris["official_site"]'
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ],
                'imageModulesData' => [
                    [
                        'mainImage' => [
                            'sourceUri' => [
                                'uri' => 'https=>//storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/google-io-2021-card.png'
                            ],
                            'contentDescription' => [
                                'defaultValue' => [
                                    'language' => 'en-US',
                                    'value' => 'Google I/O 2022 Banner'
                                ]
                            ]
                        ],
                        'id' => 'event_banner'
                    ]
                ],
                'textModulesData' => [
                    [
                        'header' => 'Gather points meeting new people at Google I/O',
                        'body' => 'Join the game and accumulate points in this badge by meeting other attendees in the event.',
                        'id' => 'game_overview'
                    ]
                ],
                'linksModuleData' => [
                    'uris' => [
                        [
                            'uri' => 'https=>//io.google/2022/',
                            'description' => 'Official I/O \'22 Site',
                            'id' => 'official_site'
                        ]
                    ]
                ]
            ];

NB:当我将示例与 Node.js 一起使用时,它工作得很好

php google-api-php-client google-wallet
2个回答
1
投票

我想我将使用 createJwtNewObjects 方法,因为它有效。


0
投票

对于到达这里的任何人:我找到了一个可能使该片段发挥作用的答案。

class.imageModulesData["event_banner"]
更改为
class.imageModulesData['event_banner']

似乎以

class.
开头的引用在某些情况下可能只能使用单引号。

© www.soinside.com 2019 - 2024. All rights reserved.