Hello everyone,

I've been working on upload photos / images to facebook fan page from an external website recently. I've found this script and apparently the demo link and the script that i've download replaced with my facebook access tokens doesn't work.

I've been playing around with the code for the last couple of days and still no chance or sign of getting this working. I'm not a facebook developer experts and i get confused with the script that i've found as well. I'm not quite sure with the page / user / app access token to be used as well.

I load the script in MAMP and couldn't even see the forms on the screen, it's pure blank and i've checked the code couple times already still couldn't see what cause the issue.

The code that i've found was from here

I've tried to contact the developer who share the script a week ago but still haven't got any responses yet. If anyone have any clues, tips or advices on how to get this working will be appreciate.

Thank you very much.

Please check the following code that i've found and used:
PHP Code:
<?php
require_once 'library/facebook.php';
$facebook = new Facebook(array(
 
'appId'  => '<app_id>',
 
'secret' => '<app_sercret>',
 
'fileUpload' => true
));
?>
<html>
<head>
<title>WebSpeaks.in | Create album and upload photos to Facebook Fan Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//It can be found at https://developers.facebook.com/tools/access_token/
$access_token '<you_access_token>';

$params = array('access_token' => $access_token);

//The id of the fanpage
$fanpage '<your_fan_page_id>';

/*
 * Go to https://developers.facebook.com/tools/explorer?method=GET&path=me%2Faccounts
 * Enter https://graph.facebook.com/me/accounts in the second text box
 * Click on submit
 * Json data will be returned
 * From that select the access token of your Fan page
*/
$page_access_token '<your_page_access_token>';
$facebook->setAccessToken($page_access_token);

$facebook->setFileUploadSupport(true);

//Create an album
$album_details = array(
        
'message'=> 'Test album',
        
'name'=> 'Album name'.date('Y-m-d H:i:s'//should be unique each time
);
$album $facebook->api('/'.$fanpage.'/albums''post'$album_details);

//The id of the album
$album_id =$album['id'];

//Replace arvind07 with your Facebook ID
$accounts $facebook->api('/arvind07/accounts''GET'$params);

foreach(
$accounts['data'] as $account) {
 if( 
$account['id'] == $fanpage || $account['name'] == $fanpage ){
  
$fanpage_token $account['access_token'];
 }
}

$valid_files = array('image/jpeg''image/png''image/gif');

if(isset(
$_FILES) && !empty($_FILES)){
 if( !
in_array($_FILES['pic']['type'], $valid_files ) ){
  echo 
'Only jpg, png and gif image types are supported!';
 }else{
  
#Upload photo here
  
$img realpath($_FILES["pic"]["tmp_name"]);

  
$args = array(
   
'message' => 'This photo was uploaded via WebSpeaks.in',
   
'image' => '@' $img,
   
'aid' => $album_id,
   
'no_story' => 0,
   
'access_token' => $fanpage_token
  
);

  
$photo $facebook->api($album_id '/photos''post'$args);
  if( 
is_array$photo ) && !empty( $photo['id'] ) ){
   echo 
'<p><a target="_blank" href="http://www.facebook.com/photo.php?fbid='.$photo['id'].'">Click here to watch this photo on Facebook.</a></p>';
  }
 }
}

?>
 <!-- Form for uploading the photo -->
 <div class="main">
  <p>Select a photo to upload on Facebook Fan Page</p>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
  <p>Select the image: <input type="file" name="pic" /></p>
  <p><input class="post_but" type="submit" value="Create album and Upload" /></p>
  </form>
 </div>
</body>
</html>