【问题标题】:How to get photos by album name Picasa and Zend GData PHP如何通过相册名称 Picasa 和 Zend GData PHP 获取照片
【发布时间】:2012-11-30 09:58:14
【问题描述】:

我无法按相册名称访问 Picasa 网络相册。我有专辑名称“我的测试专辑”。如果我使用该名称(包括空格),我会收到错误:

致命错误:带有消息的未捕获异常“Zend_Uri_Exception” '提供的 URI 无效'

没有空格“MyTestAlbum”可以正常工作:

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

这会导致错误:

// Construct the query                      
$query = $this->photos->newAlbumQuery();
$query->setUser( "default" );
$query->setAlbumName( "My Test Album" ); // This causes error

我的问题是什么字符是不允许的,所以我可以在调用setAlbumName()之前把它们去掉?

或者对更好的方法有什么建议?

谢谢 伊恩

【问题讨论】:

    标签: php zend-framework picasa zend-gdata


    【解决方案1】:

    您只能获取与特定名称匹配的专辑列表:

    // 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-08
      • 2011-05-23
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 2011-04-30
      • 2015-11-28
      • 1970-01-01
      相关资源
      最近更新 更多