src/Eccube/Controller/TopController.php line 25

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Controller;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class TopController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/", name="homepage", methods={"GET"})
  19.      * @Template("index.twig")
  20.      */
  21.     public function index()
  22.     {
  23.         $limit 8;
  24.         $instagram_business_id='17841446136341121'//①インスタグラムのビジネスID
  25.         $access_token='EAAMvVZBN3hZAkBAI4v2U7OHHbCjgZCTR9uTX0FeHY31SqVxa0gWrsd6An7qMqUAeu8ra0akKBhJBMRZA8tSeekEWnJlkntMpwzaJq63jWX8dmFjkdfPEZAHlJwCmtRPSjOOXw8KFiZCJDw5WE5kO9Te7muwyZAYMEjKWlPI7OeTFhX3AnzZCO5RA'//②無期限のフェイスブックページのアクセストークン
  26.         $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 
  27.         //echo $instagram_api_url;
  28.         $instagram_api_res = @json_decode(@file_get_contents($instagram_api_url)); //レスポンス(これをforeachとかしてリスト表示する等)
  29.         //dump($instagram_api_res);
  30.         $instaData = array();
  31.         $i 0;
  32.         foreach ( $instagram_api_res->media->data as $item )  {
  33.             $instaData[$i] =  (array)$item;
  34.             if ( $item->media_type == "VIDEO" ) {
  35.                 $instaData[$i]["type"] =  "v";
  36.                 $instaData[$i]["media_url"] = $item->thumbnail_url;
  37.             } else {
  38.                 $instaData[$i]["type"] =  "i";
  39.             }
  40.             $i++;
  41.         }
  42.         return [
  43.             'instaData' => $instaData,
  44.         ];
  45.     }
  46. }