如何从Picasa相册中提取照片?

时间:2013-03-08 12:54:21

标签: xcode ios6 picasa

我正在开发一个需要显示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;
}

但我对这段代码非常困惑。

任何人都可以提供帮助。如何启动获取照片的代码?

提前致谢。

1 个答案:

答案 0 :(得分: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)];
}