M
M
Maxim Plotnikov2021-08-13 15:57:17
PHP
Maxim Plotnikov, 2021-08-13 15:57:17

Where is the error in generating the VK widget?

Good day, I decided to try the widget generation on the community page. I took out with grief in half a community access token to update the widget. I made the code for the widget itself, but VK says that my request is incorrect, where is the error, help.

$widget_token = "token";
    $url = "https://api.vk.com/method/appWidgets.update?access_token=".$widget_token."&v=5.81";
    $code = 'return {
      		"title": "Цитата дня",
      		"title_url": "https://vk.com",
      		"title_counter": 42,
      		"more": "Читать все цитаты",
      		"more_url": "https://vk.com",
      		"text": "«Нам нужно гордиться»",
      		"descr": "Дэвид Кэмерон о победе сторонников выхода страны\n из Евросоюза на референдуме"
    };';

    $json = ['type' => 'text', 'code' => $code];

    $json = json_encode($json);

    $vk->sendMessage($peer_id, $json);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    $vk->sendMessage($peer_id, $response);

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

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

$data = ['type' => 'text', 'code' => $code];
$data = http_build_query($data);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question