0

我正在开发一个需要显示 Picasa 网络相册中的照片的应用程序。我已经搜索过了。我得到了以下链接。 https://code.google.com/p/gdata-objectivec-client/

我已经下载了 GData 并将所有必需的文件夹包含在 xcode 中。

我写的代码在这里。

- (void) loadPhotoGallery{
    username = @"xyz";
    password = @"abc";

    GDataServiceGooglePhotos  *photosService;
    photosService = [self photoService];

    NSURL *url = [GDataServiceGooglePhotos photoFeedURLForUserID:@"user" albumID:@"ablumID" albumName:nil photoID:nil kind:nil access:nil];

    GDataQueryGooglePhotos *introspectQuery;
    introspectQuery = [GDataQueryGooglePhotos photoQueryWithFeedURL:url];
    [introspectQuery setResultFormat:kGDataQueryResultServiceDocument];
    GDataServiceTicket *ticket;

    ticket = [photosService fetchFeedWithQuery:introspectQuery delegate:self didFinishSelector:@selector(introspectTicket:finishedWithServiceDocument:error:)];

}
- (void)introspectTicket:(GDataServiceTicket *)ticket
finishedWithServiceDocument:(GDataAtomServiceDocument *)serviceDoc
                   error:(NSError *)error {
    if (error == nil) {
        GDataAtomCollection *collection = [[serviceDoc primaryWorkspace] primaryCollection];
        NSArray *theMIMETypes = [collection serviceAcceptStrings];

    }
}
-(GDataServiceGooglePhotos *)photoService{
    static GDataServiceGooglePhotos *service = nil;
    username = @"xyz";
    password = @"abc";

    if (!service) {
        service = [[GDataServiceGooglePhotos alloc] init];
        [service setShouldCacheDatedData:YES];
        [service setServiceShouldFollowNextLinks:YES];
        [service setIsServiceRetryEnabled:YES];
    }
    if ([username length] > 0 && [password length] > 0) {
        [service setUserCredentialsWithUsername:username
                                   password:password];
    } else {
        // fetch unauthenticated
        [service setUserCredentialsWithUsername:nil
                                   password:nil];
    }

return service;
}

但我对这段代码很困惑。

任何人都可以帮忙。如何开始获取照片的代码?

提前致谢。

4

1 回答 1

0

我已经解决了这个问题。我做了两个改变。1. 编辑 loadPhotoGallery 方法 2. 创建新的获取照片并显示到网格中的方法。

我的 loadPhotoGallery 代码如下。

- (void) loadPhotoGallery{
    NSLog(@"fetchAllPhotos");
    GDataServiceGooglePhotos *service = [self photoService];
    GDataServiceTicket *ticket;
 NSURL *feedURL = [GDataServiceGooglePhotos photoFeedURLForUserID:@"xyz@gmail.com" albumID:@"12345" albumName:nil photoID:nil kind:nil access:nil];

 ticket = [service  fetchFeedWithURL:feedURL delegate:self didFinishSelector:@selector(photosListTicket:finishedWithFeed:error:)];

    feedURL = nil;

}

将照片显示到网格中的代码如下。

-(void)displayGrid{
    int x =0 ,y =0, counter =1;
    for (int i=0; i<[self.photos count]; i++) {

        GDataEntryPhoto *photoAlbum = [self.photos objectAtIndex:i];
        GDataTextConstruct *textConstruct = [photoAlbum title];
        NSString *stringTitle = [textConstruct stringValue];
        NSLog(@"%@",stringTitle);
        GDataMediaGroup *mediaGroup = [photoAlbum mediaGroup];
        NSArray *arrMediaThumbs = [mediaGroup mediaThumbnails];

        GDataMediaThumbnail *mediaThumbnail =[arrMediaThumbs objectAtIndex:2];
        NSLog(@"%@", [mediaThumbnail URLString]);

        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[mediaThumbnail URLString]]];
        UIImage *img = [UIImage imageWithData:data];
        UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
        imgView.frame = CGRectMake(x, y, 106, 106);
        [scrPhoto addSubview:imgView];

        UIButton *btn= [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = imgView.frame;
        btn.tag = counter;
        [btn addTarget:self action:@selector(btnPhotoClicked:) forControlEvents:UIControlEventTouchUpInside];
        [scrPhoto addSubview:btn];
        if(counter %3 == 0 ){
            y = y +106;
            x = 0;
        } else{
            x =x + 106;
        }
        counter++;

    }
    [scrPhoto setContentSize:CGSizeMake(320, y)];
}
于 2013-03-13T12:51:47.467 回答