我正在尝试使用PHP和Google API将数据推送到Firestore数据库.
在我在网上看到的文档和示例中,我能够在发送数据时使用mapValue和arrayValue.
我使用的示例如下:
[
"orderName" => [
"stringValue" => "Gbeila Aliu Wahab"
],
"orderLocationName" => [
"stringValue" => "Accra Mall Limited"
],
"orderTotalAmount" => [
"doubleValue" => 150.5
],
"orderDescription" => [
"stringValue" => "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
],
"orderLocationGeoPoints" => [
"geoPointValue" => (object) [
"latitude" => 5.5557,
"longitude" => -0.1963
]
],
"orderStatus" => [
"stringValue" => "NotAssigned"
],
]
这工作得很好,但是当我尝试发送对象或数组时,出现以下错误返回给我:
"message": "Invalid JSON payload received. Unknown name \"map_value\" at 'document.fields[0].value': Proto field is not repeating, cannot start list.",
尝试使用以下代码映射值时:-
"orderName" => [
"mapValue" => ["Gbeila Aliu Wahab", 123]
]
// or
"orderName" => [
"arrayValue" => [
"first" => [
"stringValue" => "test"
],
"second" => [
"stringValue" => "test123"
]
]
]
我尝试了许多变体来尝试使它起作用.
我应该如何使用mapValue和arrayValue我可以看到很多有关value选项的提及,但是我看不到任何有关如何使用它们的示例.
任何帮助将不胜感激.
解决方法:
根据the documentation.,正在生成的数组或映射的有效载荷不正确.您需要将实际数据(要存储)包装在values键下,最终数组应为:
["orderName" => ["arrayValue" => ["values" => [["stringValue" => "test"], ["stringValue" => "test123"]]]]]
同样,您的mapValue应该为
["orderName" => ["mapValue" => ["fields" => ["field1" => ["stringValue" => "Gbeila Aliu Wahab"]]]]]
另外,您可以通过this package.与其他数据映射器一起玩