【发布时间】:2012-03-15 14:26:21
【问题描述】:
我正在尝试在 iphone 上获取 picasa 网络相册,已从 google.code 下载了代码和示例,但遇到了一个问题,即获取相册提要返回给我的提要对象类型错误 - 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];
}
}
}
}
这是每个相册照片提要获取的回调:
// 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]);
}
}
}
问题在于最后一个回调中的提要中的条目不是 GDataEntryPhoto 类型,只是基本 GDataEntryBase - 因此尝试访问它们的缩略图 url 会使应用程序崩溃。 该代码是从 google 的 cocoa (non-touch) 示例中复制而来的,并且可以正常工作 - 返回的提要填充了 GDateEntryPhoto 对象。
任何帮助将不胜感激。
【问题讨论】:
标签: iphone ios cocoa-touch gdata-api picasa