Facebook api

De Marmits Wiki

Albums photos facebook dans une page web

//CONTROLEUR

<?php
  public function photosAction()
    {
            include "facebook.php";  // bibliotheque facebook intégrée avec set_include_path()
            $facebook = new Facebook(array(
              'appId'  => 'App ID  ',
              'secret' => 'App Secret',
            ));
            
            // Get User ID
            $user = $facebook->getUser();
            // We may or may not have this data based on whether the user is logged in.
            //
            // If we have a $user id here, it means we know the user is logged into
            // Facebook, but we don't know if the access token is valid. An access
            // token is invalid if the user logged out of Facebook.
            if ($user) {
              try {
                // Proceed knowing you have a logged in user who's authenticated.
                $user_profile = $facebook->api('/me');
              } catch (FacebookApiException $e) {
                error_log($e);
                $user = null;
              }
            }
            // This call will always work since we are fetching public data.
            $profil = $facebook->api('/profil id');
            $profilalbum = $facebook->api('/profil id/albums');
            $this->view->facebookname = $profil['name'];
            $dataAlbums = $profilalbum['data'];
            
            $nbData = count($dataAlbums);
            $this->view->nbData = $nbData;
            $i = 0;
            while($i < $nbData)
            {
                $tabData[$i]['name'] = htmlentities($dataAlbums[$i]['name'], ENT_QUOTES, "UTF-8");
                $tabData[$i]['link'] = htmlentities($dataAlbums[$i]['link'], ENT_QUOTES, "UTF-8");
                $tabData[$i]['cover_photo'] = htmlentities($dataAlbums[$i]['cover_photo'], ENT_QUOTES, "UTF-8");
                $i++;
            }
            $this->view->tabData = $tabData;
  }
?>