获取GDataFeedPhotoAlbum返回错误的对象类型

时间:2012-02-25 08:37:11

标签: iphone ios cocoa-touch gdata-api picasa

我正在尝试在iphone上获取picasa网络相册,已经从google.code下载了代码和示例但遇到了一个问题,即提取相册Feed会返回错误对象类型的Feed - GDataEntryBase 而不是 GDataEntryPhoto

这是我正在使用的代码:

首先,我打电话给我以获取我的所有专辑:

- (void)fetchAllAlbums 
{
    NSLog(@"Fetching all albums");

    //request albums
    GDataServiceTicket *ticket;    
    NSURL *feedURL = [GDataServiceGooglePhotos photoFeedURLForUserID:myemail
                                                             albumID:nil
                                                           albumName:nil
                                                             photoID:nil
                                                                kind:nil
                                                              access:nil];
    ticket = [_GooglePhotoService fetchFeedWithURL:feedURL
                                          delegate:self
                                 didFinishSelector:@selector(albumListFetchTicket:finishedWithFeed:error:)];
    [self set_AlbumFetchTicket: ticket];
}

现在,在回调中,我打电话来获取每张返回相册的所有照片:

- (void)albumListFetchTicket:(GDataServiceTicket *)ticket
            finishedWithFeed:(GDataFeedPhotoUser *)feed
                       error:(NSError *)error 
{
    [self set_UserAlbumFeed: feed];
    [self set_AlbumFetchError:error];
    [self set_AlbumFetchTicket:nil];

    if (error == nil) {
        NSLog(@"Got albums!");

        for (GDataEntryPhotoAlbum * albumEntry in _UserAlbumFeed)
        {
            NSLog(@"Album Title: %@", [[albumEntry title] stringValue]);
            {
                NSLog(@"Fetching photos!");

                [self set_AlbumPhotosFeed:nil];
                [self set_PhotosFetchError:nil];
                [self set_PhotosFetchTicket:nil];

                GDataServiceTicket *ticket;
                ticket = [_GooglePhotoService fetchFeedWithURL: [[albumEntry feedLink] URL]
                                                      delegate: self
                                             didFinishSelector: @selector(photosTicket:finishedWithFeed:error:)];

                [self set_PhotosFetchTicket:ticket];

            }
        }
    }
}

这是每张专辑照片Feed fetch的回调:

// photo list fetch callback
- (void)photosTicket:(GDataServiceTicket *)ticket
    finishedWithFeed:(GDataFeedPhotoAlbum *)feed
               error:(NSError *)error 
{
    //tell me what class you are
    NSLog(@"Feed class: %@", NSStringFromClass([feed class]));

    [self set_AlbumPhotosFeed:   feed];
    [self set_PhotosFetchError:  error];
    [self set_PhotosFetchTicket: ticket];

    if (error == nil)
    {
        NSLog(@"Got Photos!");

        for (GDataEntryPhoto * photo in feed)
        {
            NSLog(@"Title: %@", [[photo title] stringValue]);

            //tell me what class you are
            NSLog(@"%@", NSStringFromClass([photo class]));

            //NSArray * thumbnails = [[photo mediaGroup] mediaThumbnails];
            //NSLog(@"thumbnails count: %d", [thumbnails count]);
            //NSLog(@"Photo thumnail url: %@", [[thumbnails objectAtIndex:0] URLString]);
        }            
    }
}

问题是最后一个回调中的Feed中的条目不是GDataEntryPhoto类型,只是基本GDataEntryBase - 因此尝试访问其缩略图URL会使应用程序崩溃。 该代码是从谷歌的可可(非触摸)示例中复制的,并且它可以正常工作 - 返回的Feed填充了GDateEntryPhoto对象。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

-ObjC -all_load添加到xcodeproject中的其他链接标记,然后将SystemConfiguration.frameworkCFNetwork.frameworkSecurity.framework添加到构建阶段< / strong> - &gt; 使用二进制文件链接库