Я пытаюсь создать новый слайд, содержащий таблицу с некоторыми данными, используя API Google Slides. Я получаю неверную ошибку полезной нагрузки JSON.
Я попытался создать функцию, которая выполняет запрос новой таблицы.
def make_table_obj(self, data):
'''make a table object to be added to a slide'''
keys = [key for key in data[0].keys()]
return {
"objectId": gen_id(),
"pageType": "SLIDE",
"pageElements": [
{"elementGroup": {
"table": {
"rows": len(data),
"columns": len(data[0].keys()),
"tableRows": [
[
{
"text": data[i][keys[k]],
"location": {"rowIndex": i, "columnIndex": k}
} for k in range(int(len(keys)))
]
for i in range(int(len(data)))
]}
}}]
}
Вот несколько примеров данных, которые помогут мне
[{'_id': 'Customer Service',
'metric1': 239.0,
'metric2': 1875.0},
{'_id': 'Order',
'metric1': 2846.0,
'metric2': 5171.0},
{'_id': 'Checkout',
'metric1': 1789.0,
'metric2': 2446.0}]
Функция выдает запрос, который мне нужен (я думаю), но я получаю эту ошибку.
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://slides.googleapis.com/v1/presentations/<presentationId>:batchUpdate?alt=json returned "Invalid value at 'requests[1].create_shape.shape_type' (type.googleapis.com/google.apps.slides.v1.Shape.Type), "Table"
Invalid JSON payload received. Unknown name "rows" at 'requests[1].create_shape.element_properties': Cannot find field.
Invalid JSON payload received. Unknown name "columns" at 'requests[1].create_shape.element_properties': Cannot find field.
Invalid JSON payload received. Unknown name "tableRows" at 'requests[1].create_shape.element_properties': Cannot find field.". Details: "[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'requests[1].create_shape.shape_type', 'description': 'Invalid value at \'requests[1].create_shape.shape_type\' (type.googleapis.com/google.apps.slides.v1.Shape.Type), "Table"'}, {'field': 'requests[1].create_shape.element_properties', 'description': 'Invalid JSON payload received. Unknown name "rows" at \'requests[1].create_shape.element_properties\': Cannot find field.'}, {'field': 'requests[1].create_shape.element_properties', 'description': 'Invalid JSON payload received. Unknown name "columns" at \'requests[1].create_shape.element_properties\': Cannot find field.'}, {'field': 'requests[1].create_shape.element_properties', 'description': 'Invalid JSON payload received. Unknown name "tableRows" at \'requests[1].create_shape.element_properties\': Cannot find field.'}]}]">
Вот полный запрос, который я отправляю.
[
{
"objectId": "id-1617143529-776043",
"pageType": "SLIDE",
"pageElements": [
{
"elementGroup": {
"table": {
"rows": 23,
"columns": 3,
"tableRows": [
[
{
"text": "Customer Service",
"location": {
"rowIndex": 0,
"columnIndex": 0
}
},
{
"text": 239.0,
"location": {
"rowIndex": 0,
"columnIndex": 1
}
},
{
"text": 1875.0,
"location": {
"rowIndex": 0,
"columnIndex": 2
}
}
],
[
{
"text": "Order",
"location": {
"rowIndex": 1,
"columnIndex": 0
}
},
{
"text": 2846.0,
"location": {
"rowIndex": 1,
"columnIndex": 1
}
},
{
"text": 5171.0,
"location": {
"rowIndex": 1,
"columnIndex": 2
}
}
],
[
{
"text": "Checkout",
"location": {
"rowIndex": 2,
"columnIndex": 0
}
},
{
"text": 1789.0,
"location": {
"rowIndex": 2,
"columnIndex": 1
}
},
{
"text": 2446.0,
"location": {
"rowIndex": 2,
"columnIndex": 2
}
}
],
]
}
}
}
]
}
]
Заранее спасибо, если вы можете помочь, я знаю, что этот вопрос слишком длинный.