Question

I am developing an application which need to display photos from Picasa web album. I have search about it. I got following links. https://code.google.com/p/gdata-objectivec-client/

I have downloaded GData and also included all required folder into xcode.

The code which i have written is here.

- (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;
}

But i am very confused with this code.

Can anyone help. how to start code for fetching photos?

Thanks in advance.

Was it helpful?

Solution

I have resolve this. I have make two changes. 1. Edit loadPhotoGallery method 2. Create new method for fetching photos and displayed into grid.

My code for loadPhotoGallery is following.

- (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;

}

And code for displaying Photos into Grid is following.

-(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)];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top