Archivo phpcUrl.php
Código PHP :
<?php class FacePageAlbum { private $URL; private $TOKEN; private $PAGE; private $PHOTOS; private function setPage() { $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'; $this->PAGE = $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; } private function setAlbumUrl($id) { if(is_numeric($id)) { if($this->TOKEN) { $this->URL = "http://graph.facebook.com/".$id."/albums?".$this->TOKEN; return true; } else { $this->URL = "http://graph.facebook.com/".$id."/albums"; return true; } } else { return false; } } private function setToken($appId, $appSecret) { $this->TOKEN = $this->curlGetFile('https://graph.facebook.com/oauth/access_token?type=client_cred&client_id='.$appId.'&client_secret='.$appSecret); } public function FacePageAlbum($id, $albumId, $aurl, $appId, $appSecret) { $this->setPage(); if($id) { if($appId && $appSecret) $this->setToken($appId, $appSecret); $this->setAlbumUrl($id); if($albumId && $this->albumChk($albumId)) { $this->PHOTOS = 'http://graph.facebook.com/'.$albumId.'/photos'; $json = json_decode($this->curlGetFile($this->PHOTOS)); if($json -> error) die("THERE HAS BEEN AN ERROR:album id invalid"); echo '<a id="back" href="javascript:history.go(-1)">Go Back</a>'; echo '<a id="backAlbums" href="'.$this->PAGE.'">Back to albums</a>'; echo '<br clear="all" />'; if($json->paging->previous) echo '<a id="prev" href="'.$PAGE.'?aurl='.urlencode($json->paging->previous).'">Previous</a>'; if($json->paging->next) echo '<a id="next" href="'.$PAGE.'?aurl='.urlencode($json->paging->next).'">Next</a>'; echo '<br clear="all" />'; foreach($json->data as $v) { echo "<a class='ImageLink' href = '".$v->source."'><img width='110px' src='".$v->picture."' /></a>"; } return true; } else if ($aurl) { $this->PHOTOS = urldecode($aurl); $json = json_decode($this->curlGetFile($this->PHOTOS)); if($json -> error) die("THERE HAS BEEN AN ERROR: album url invalid"); echo '<a id="back" href="javascript:history.go(-1)">Go Back</a>'; echo '<a id="backAlbums" href="'.$this->PAGE.'">Back to albums</a>'; echo '<br clear="all" />'; if($json->paging->previous) echo '<a id="prev" href="'.$PAGE.'?aurl='.urlencode($json->paging->previous).'">Previous</a>'; if($json->paging->next) echo '<a id="next" href="'.$PAGE.'?aurl='.urlencode($json->paging->next).'">Next</a>'; echo '<br clear="all" />'; foreach($json->data as $v) { echo "<a class='ImageLink' href = '".$v->source."'><img width='110px' src='".$v->picture."' /></a>"; } return true; } else { $json = json_decode($this->curlGetFile($this->URL)); if($json -> error) die("THERE HAS BEEN AN ERROR: pageId invalid"); foreach($json->data as $v) { echo "<div class ='ImgWrapper'>"; echo "<div style = 'width:125px; height:120px;overflow:hidden'> <img width='125px' src='https://graph.facebook.com/".$v->id."/picture' /> </div>"; echo $v->from->name."<br>"; echo "<a href = '".$this->PAGE; echo "?"; echo "aid=".$v->id."'>".$v->name."</a>"; echo "<br>Num of images:".$v->count."<br>"; echo "<br clear='all'></div>"; } return true; } } return false; } public function curlGetFile($curlUrl) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $curlUrl); $data = curl_exec($ch); curl_close($ch); return $data; } public function albumChk($albumId) { $json = json_decode($this->curlGetFile($this->URL)); $arrayId = array(); foreach($json->data as $v) array_push($arrayId, $v->id); if(!in_array($albumId,$arrayId)) return false; return true; } }; ?>
index.php
Código PHP :
<?php include("phpcUrl.php"); ?> <html> <head> <title>Álbum de fotos Facebook</title> <style type='text/css'> body { width:auto; font-family:arial; } #wrapper { width:200px; } #back { display:block; padding:5px; float:left; } #backAlbums { display:block; padding:5px; float:right; } #next { float:right; display:block; padding:5px; } #prev { float:left; display:block; padding:5px; } .ImageLink { display:block; float:left; padding:5px; margin:5px; } .ImgWrapper { width:100px; height: auto; } .ImageLink img { width:100px; } </style> </head> <body> <table width="0" border="0"> <tr> <td><div id ="wrapper"> <?php //donde van los 0000 tiene que ir el ID de tu fanpage // define('PAGE_ID','000000000000'); define('APP_ID',''); define('APP_SECRET',''); $face = new FacePageAlbum(PAGE_ID, $_GET['aid'], $_GET['aurl'], APP_ID, APP_SECRET); ?></td> <td><div id ="ImgWrapper"> </td> </tr> </table> </div> </body> </html>
Resulta que tengo el siguiente problemas con el código, yo quiero que mas imagines previas se vean igual que en facebook, es decir que de 4 en 4 y cuando acceden al albun igual se vean así, el problema es que en el álbum por medio de css puedo mostrarlos así, pero en el índex solo aparece un loop infinito y se ve mal, alguna idea de como solucionarlo?