Tell me more ×
SmugMug Stack Exchange is a question and answer site for SmugMug developers and end users. It's 100% free, no registration required.

I am using the following code, but no matter how I structure the array for the images_get method, it never passes the AlbumID correctly..any clues??

<?php

require_once( "phpSmug.php" );
$albumid = $_POST['id1'];
$albumkey = $_POST['id2'];
try {
$mug = new phpSmug( "APIKey=***********", "AppName=****" );

$mug->login();  

$images = $mug->images_get(array("AlbumID" => $albumid, "AlbumKey" => $albumkey, "Heavy" => "1" ));
$images = ( $mug->APIVer == "1.2.2" ) ? $images['Images'] : $images;

foreach ( $images as $image ) {
    echo '<a href="'.$image['MediumURL'].'"><img src="'.$image['TinyURL'].'" title="'.$image['Caption'].'" alt="'.$image['id'].'" /></a>';
}
}
catch ( Exception $e ) {
echo "{$e->getMessage()} (Error Code: {$e->getCode()})";
}
?>

Thanks in advannce!!!

share|improve this question
A few suggestions only, since the main problem seems solved already: You can pass a APIVer value to phpSmug during initilaization, negating the need to test for version. You might also want to add a linebreak like PHP_EOL inside the foreach loop to clean up the output source :P – HaavardH Jun 21 '12 at 10:02
Thank you for the tips! – Jjames Jun 21 '12 at 16:10

1 Answer

up vote 1 down vote accepted

There's nothing wrong with your code. I've tested this (without using $_POST) and it works a treat.

I believe all you need to do is verify the $_POST variables are populated as you expect them to be later in the code.

One other tip: watch out for

$images = ( $mug->APIVer == "1.2.2" ) ? $images['Images'] : $images;

This will apply for 1.2.2 and 1.3.0 as the API responds the same way for both.

share|improve this answer
Thanks again for your help! – Jjames Jun 19 '12 at 19:34
Further to this, you technically shouldn't need that line any more as all API endpoints below 1.2.2 are technically deprecated as far as I know. – lildude Jun 20 '12 at 8:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.