O
O
ojiekcahdp2021-08-03 23:30:57
JavaScript
ojiekcahdp, 2021-08-03 23:30:57

VK API appWidgets.update how to send code correctly?

I want to send for example

{
    "title": "My Table",
    "title_url": "https://link",
    "title_counter": 31,
    "more": "Посмотреть все результаты",
    "more_url": "https://link2",
    "head": [{
        "text": "Название первой колонки"
    }, {
        "text": "Название второй колонки",
        "align": "center"
    }],
    "body": [
        [{
            "text": "Это первая ячейка первой строки",
            "icon_id": "3484735_23434324"
        },
        {
            "text": "Это вторая ячейка первой строки",
            "url": "https://vk.com/wall-12345_542321"
        }],
        [{
            "text": "Это первая ячейка второй строки",
            "icon_id": "3484735_23434324"
        },
        {
            "text": "Это вторая ячейка второй строки",
            "url": "https://vk.com/wall-12345_54321"
        }
        ]
    ]
}


I do like this:
vk.api.appWidgets.update({

type: `Table`,
code:  //code

})

How can I send the above code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2021-08-04
@StockholmSyndrome

https://vk.com/dev/apps_widgets

code must return a JSON object describing the widget. Widget elements can contain only internal links to vk.com (except away.php) and vk.me.
In general, the code parameter looks like this:
return {
    widget
};

Judging by this description from the documentation, you need to send it like this:
const widget = {
    "title": "My Table",
    "title_url": "https://link",
    "title_counter": 31,
    // ...
};

vk.api.appWidgets.update({
    type: `Table`,
    code: 'return ' + JSON.stringify(widget) + ';'
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question