问题
Background
I would like to list all the albums for my account that match a given name.
Problem
After deleting an album, then recreating an album with the exact same name, the code for $albumQuery->setAlbumName( ... )
to find the album name fails with a 404, even though the album was successfully created.
The following code runs fine:
// This is correct -- adding photographs to albums works.
$client = $this->login( $user, $pass, $picasa );
$picasa = $this->newPhotographService( $client );
$albumQuery = $picasa->newAlbumQuery();
$albumQuery->setUser( $user );
$albumQuery->setAlbumName( "17" ); // This is the literal name of the album.
$albumQuery->setMaxResults( 10 );
This line, which exists immediately after the call to setMaxResults
, fails:
$albumFeed = $picasa->getAlbumFeed( $albumQuery );
Upon executing the above line the following error occurs:
Exception: Expected response code 200, got 404
Update #1
The following code works, but not consistently:
echo "Search for the album named $accountId for $user\n";
$albumQuery = $picasa->newAlbumQuery();
$albumQuery->setUser( $user );
$albumQuery->setAlbumName( "ALBUM17" );
$albumQuery->setMaxResults( 1 );
$albumId = null;
try {
echo "\nGet album feed from albumQuery.\n";
$albumFeed = $picasa->getAlbumFeed( $albumQuery );
// The feed returns a list of photos; each photo has an album ID.
foreach( $albumFeed as $key => $entry ) {
$albumId = $entry->getGphotoAlbumId();
}
echo "\nFound album ID: ALBUM17\n";
}
catch( Zend_Gdata_App_Exception $ex ) {
echo "\nError: " . $ex->getMessage() . "\n";
echo "\nCreate album.\n";
// Create the album.
$albumId = $this->createAlbum( $picasa, "ALBUM17" );
echo "\nCreated album ID: ALBUM17\n";
}
This performs as expected until the album is deleted. When recreating an album that has been deleted, it seems the API cannot find the recreated name. The result is that the above code creates new albums with the same name, which is undesirable.
Update #2
This appears to be a bug; I have logged an issue:
https://code.google.com/p/gdata-issues/issues/detail?id=4516
Question
How do you retrieve an album ID using Picasa's PHP API for an album that was deleted and then recreated?
回答1:
I'm not familiar with this particular API however...
What usually happens is that you CANNOT recreate an entry. Once you delete it, it's gone.
So you need to do is to get the id of the new album you just created, and then use that in your code.
It also seems you're confusing the album's name with it's id.
来源:https://stackoverflow.com/questions/16352676/list-recreated-album-names-that-were-previously-deleted