<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Eccube\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
class TopController extends AbstractController
{
/**
* @Route("/", name="homepage", methods={"GET"})
* @Template("index.twig")
*/
public function index()
{
$limit = 8;
$instagram_business_id='17841446136341121'; //①インスタグラムのビジネスID
$access_token='EAAMvVZBN3hZAkBAI4v2U7OHHbCjgZCTR9uTX0FeHY31SqVxa0gWrsd6An7qMqUAeu8ra0akKBhJBMRZA8tSeekEWnJlkntMpwzaJq63jWX8dmFjkdfPEZAHlJwCmtRPSjOOXw8KFiZCJDw5WE5kO9Te7muwyZAYMEjKWlPI7OeTFhX3AnzZCO5RA'; //②無期限のフェイスブックページのアクセストークン
$instagram_api_url='https://graph.facebook.com/v14.0/'.$instagram_business_id.'?fields=name,media.limit(' . $limit . '){caption,media_url,thumbnail_url,permalink,like_count,comments_count,media_type}&access_token='.$access_token; //APIへのリクエストURL
//echo $instagram_api_url;
$instagram_api_res = @json_decode(@file_get_contents($instagram_api_url)); //レスポンス(これをforeachとかしてリスト表示する等)
//dump($instagram_api_res);
$instaData = array();
$i = 0;
foreach ( $instagram_api_res->media->data as $item ) {
$instaData[$i] = (array)$item;
if ( $item->media_type == "VIDEO" ) {
$instaData[$i]["type"] = "v";
$instaData[$i]["media_url"] = $item->thumbnail_url;
} else {
$instaData[$i]["type"] = "i";
}
$i++;
}
return [
'instaData' => $instaData,
];
}
}