2012-11-30 38 views
2

我無法按專輯名稱訪問Picasa網絡相冊。我有專輯名稱「我的測試相冊」。如果我使用該名稱(包括空格)我收到錯誤:如何按專輯名稱Picasa和Zend GData獲取照片PHP

Fatal error: Uncaught exception 'Zend_Uri_Exception' with message 'Invalid URI supplied'

不含空格 'MyTestAlbum' 正常工作:

// Construct the query      
$query = $this->photos->newAlbumQuery(); 
$query->setUser("default"); 
$query->setAlbumName("MyTestAlbum"); //This works fine 

這將導致錯誤:

我問題是什麼字符是不允許的,所以我可以在撥打setAlbumName()之前刪除它們?

或者有更好方法的建議嗎?

感謝 伊恩

回答

0

你只能得到符合特定名稱專輯列表:

// Find the album for the given accountId. 
$albumQuery = $picasa->newAlbumQuery(); 
$albumQuery->setUser($user); 
$albumQuery->setAlbumName("AlbumName"); // No spaces. 
$albumQuery->setMaxResults(1); 

$albumId = null; 

try { 
    $albumFeed = $picasa->getAlbumFeed($albumQuery); 

    foreach($albumFeed as $key => $entry) { 
    $albumId = $entry->getGphotoAlbumId(); 
    } 
} 
catch(Zend_Gdata_App_Exception $ex) { 
    // Create the album because the album name could not be found. 
    $albumId = $this->createAlbum($picasa, "AlbumName"); 
} 

在這一點上,$albumId應該引用一個有效的專輯。

該代碼遍歷專輯提要。您必須確保專輯名稱唯一標識;否則代碼將返回與名稱匹配的多個專輯。

請注意,如果您刪除了一個相冊,然後重新創建了一個相同名稱的相冊,則會有一個錯誤,阻止您檢索該相冊。另見:List recreated album names that were previously deleted

相關問題