Giacomo Torricelli
Giacomo Torricelli

Reputation: 763

FB Developer: Uncaught OAuthException: (#120) Invalid album id

i'm trying to post photos on a fanpage and I get this error:

Fatal error: Uncaught OAuthException: (#120) Invalid album id thrown in /home/eyikmdnu/public_html/jack/facebook-sdk/base_facebook.php on line 1264

This is the code of the page (obv the token, the secret etc are not the "original"

require_once("../facebook-sdk/facebook.php");

    define("APP_ID", "*****");
    define("APP_SECRET", "********");

    $fanpage_token = "*******";

    $user_access_token = "********";    


    $config = array(
      'appId' => APP_ID,
      'secret' => APP_SECRET,
      'fileUpload' => true // optional
     );
  $facebook = new Facebook($config);

    //pagina = 358226040977616
    //album id =  402459486554271


  //$access_token = $_POST['access_token'];
  //echo $access_token;

  $facebook->setAccessToken($fanpage_token); 
  echo "Access Token Settato <br>\n";

  $facebook->setFileUploadSupport(true);
  echo "setFileUploadSupport(true) settato <br>\n";

  $img_url = "images/jack.png";
  //$img_url = $_POST['url'];
  echo "$img_url = $img_url <br>\n";

  $page_id = "358226040977616";
  $album_id = "402459486554271";
  echo "Page id: $page_id <br>\n";
  echo "Album id: $album_id <br>\n";

  $real_img_url = realpath($img_url);
  echo "Real img url: $real_img_url <br>\n";

  $args = array(
    'message' => 'message to write in legend',
    'image' => "@" . $img_url,
    'aid' => $album_id,
    'no_story' => 1,
    'access_token' => $fanpage_token
    );

  echo "<br>\n";
  print_r($args);
  echo "<br>\n";

  $photo = $facebook->api("/".$album_id."/photos", 'post', $args);
  print_r($photo);

Need help! :O

Upvotes: 1

Views: 631

Answers (1)

Giacomo Torricelli
Giacomo Torricelli

Reputation: 763

I solved, the problem is that I should use the access_token of the page, that is not static, well I have to look in my /profile/accounts

$params = array('access_token' => $access_token);
$accounts = $facebook->api('/giacomo.torricelli/accounts', 'GET', $params);

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

Thanks

Upvotes: 1

Related Questions