modx from curl (json) to tpl

PHOTO EMBED

Thu Jun 24 2021 13:53:56 GMT+0000 (UTC)

Saved by @vskand #modx #instagram #curl #json #array #tpl

<?php
$url = "https://graph.instagram.com/me/media?access_token=IGQVJWVGM5azZApYkEwTENxQ19kbWdmS1dfeWxJcUk2VzJobF92LWE5NTdsNlV0dGFoNGw2bkRMZATh2SnFzcGVOeDJXNVNzcUoyS3pOY2taZA3BfX25sUHA3VXVHUlBTNFVGVHp1aEktOUxXbDlpV3cxeAZDZD&fields=media_url,media_type,caption,permalink";
// create curl resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, $url);

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string
$instagramData = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch); 

$instagramData = json_decode($instagramData, true); // true = to array έστω
$instagramData = $instagramData['data'];

$tpl = 'instagramFeedTPL';
$out = '';

foreach ($instagramData as $data)
{
    if ($data['media_type'] == 'VIDEO')
    {
        $data['isVideo'] = 1;
    }
    
    $out .= $modx->getChunk($tpl, $data);
}


return $out;
content_copyCOPY