Проблемы со сниппетом

Возникли проблемы с API.
В сниппете не я не указывал версию, по которой запрашивали с VK. Вроде как выдавало старой версией.
Сейчас смотрю. Не выводятся результаты.

Тогда
Посмотрел, что в echo query;
Результат:
{«error»:{«error_code»:8,«error_msg»:«Invalid request: v (version) is required»,«request_params»:[{«key»:«oauth»,«value»:«1»},{«key»:«method»,«value»:«photos.get»},{«key»:«owner_id»,«value»:"-85317162"},{«key»:«album_id»,«value»:«244474587»},{«key»:«rev»,«value»:«1»},{«key»:«extended»,«value»:«0»},{«key»:«feed_type»,«value»:«photo»},{«key»:«count»,«value»:""}]}}
Вот я думаю он ругается на версию.
Написал в строку
$query = file_get_contents('https://api.vk.com/method/photos.get?owner_id=-'.$owner_id.'&album_id='.$album_id.'&rev='.$rev.'&extended='.$extended.'&feed_type='.$feed_type.'&count='.$count.'&v=5.73');
последнюю версию.
Тогда результат есть prntscr.com/ihu6qr

Убираю echo $query; и страница вешается HTTP ERROR 500.

Вот такой код. Упрощённая код для теста.
<?php
// VK API
    $owner_id = $modx->getOption('owner_id', $scriptProperties, '85317162'); // Группа
    $album_id = $modx->getOption('album_id', $scriptProperties, '244474587'); // Альбом
    $rev = $modx->getOption('rev', $scriptProperties, '1'); // 1 новые сверху
    $extended = $modx->getOption('extended', $scriptProperties, '0'); // Расширенные поля
    $feed_type = $modx->getOption('feed_type', $scriptProperties, 'photo'); // photo, photo_tag
    $count = $modx->getOption('count', $scriptProperties, ''); // Количество загружаемых фото
    $class = $modx->getOption('class', $scriptProperties, '');
    $tpl = $modx->getOption('tpl', $scriptProperties, '@INLINE <li><img src="[[+photo_75]]"></li>');
    
    $query = file_get_contents('https://api.vk.com/method/photos.get?owner_id=-'.$owner_id.'&album_id='.$album_id.'&rev='.$rev.'&extended='.$extended.'&feed_type='.$feed_type.'&count='.$count.'&v=5.73');
    $result = json_decode($query, true); // Декодируем полученный json массив
    
    //echo $query;
    $response = $result['response'];
    $output = '';
    $pdo = $modx->getService('pdoTools');
    
    foreach ($response as $res) {    
        $res['class'] = $class;
        $output .= $pdo->getChunk($tpl, $res);
    }
    return $output;
Дмитрий
21 февраля 2018, 14:39
modx.pro
1 928
0

Комментарии: 2

Дмитрий
21 февраля 2018, 17:54
0
Fatal error: Uncaught TypeError: Argument 2 passed to pdoTools::getChunk() must be of the type array, integer given, called in /home/o/oooakg/kulibin.club/public_html/core/cache/includes/elements/modsnippet/102.include.cache.php on line 27 and defined in /home/o/oooakg/kulibin.club/public_html/core/components/pdotools/model/pdotools/pdotools.class.php:403 Stack trace: #0 /home/o/oooakg/kulibin.club/public_html/core/cache/includes/elements/modsnippet/102.include.cache.php(27): pdoTools->getChunk('@INLINE <im...', 24) #1 /home/o/oooakg/kulibin.club/public_html/core/model/modx/modscript.class.php(70): include('/home/o/oooakg/...') #2 /home/o/oooakg/kulibin.club/public_html/core/model/modx/modparser.class.php(534): modScript->process(NULL) #3 /home/o/oooakg/kulibin.club/public_html/core/components/pdotools/model/pdotools/pdoparser.class.php(273): modParser->processTag(Array, true) #4 /home/o/oooakg/kulibin.club/public_html/core/model/modx/modparser.class.php(250): pdoParser->processTag(Array, true) #5 /home/o/oooakg/kulib in /home/o/oooakg/kulibin.club/public_html/core/components/pdotools/model/pdotools/pdotools.class.php on line 403
    Дмитрий
    21 февраля 2018, 18:12
    0
    Подсказали решение.
    $response = $result['response']['items'];

    Вообщем. Работающий код с новой версией api теперь такой. Пагинация и кеширование(за это спасибо Алексею Ерохину).
    <?php
    // VK API
        //ini_set('error_reporting', E_ALL);
        //ini_set('display_errors', 1);
        //ini_set('display_startup_errors', 1);
        $owner_id = $modx->getOption('owner_id', $scriptProperties, '0'); // Группа
        $album_id = $modx->getOption('album_id', $scriptProperties, '0'); // Альбом
        $rev = $modx->getOption('rev', $scriptProperties, '1'); // 1 - новые сверху
        $extended = $modx->getOption('extended', $scriptProperties, '0'); // Расширенные поля
        $feed_type = $modx->getOption('feed_type', $scriptProperties, 'photo'); // photo, photo_tag
        $count = $modx->getOption('count', $scriptProperties, ''); // Количество загружаемых фото
        $class = $modx->getOption('class', $scriptProperties, '');
        $tpl = $modx->getOption('tpl', $scriptProperties, '@INLINE <li><img src="[[+src_bigxx]]"></li>');
        
        $response = $modx->cacheManager->get('vk_photos_'.$modx->resource->id, [xPDO::OPT_CACHE_KEY => 'vk_photos']);
        if(empty($response) || $request['refresh'] == 1) {
            // Получаем фото с ВК
            $query = file_get_contents('https://api.vk.com/method/photos.get?owner_id=-'.$owner_id.'&album_id='.$album_id.'&rev='.$rev.'&extended='.$extended.'&feed_type='.$feed_type.'&count='.$count.'&v=5.73');
            $result = json_decode($query, true); // Декодируем полученный json массив
            
            $response = $result['response']['items'];
            $photos= $modx->cacheManager->set('vk_photos_'.$modx->resource->id, $response, 3600, [xPDO::OPT_CACHE_KEY => 'vk_photos']);
        }
        
        $pdo = $modx->getService('pdoTools');
        
        $modx->setPlaceholder($totalVar, count($response));
        $response = array_slice($response, $offset, $limit, true);
        
        foreach ($response as $res) {    
            $res['class'] = $class;
            $output .= $pdo->getChunk($tpl, $res);
        }
        return $output;
    Вывод описан тут vk.com/dev/photo
      Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
      2