2013-03-08 5 views
0

Picasa 웹 앨범에서 사진을 표시해야하는 응용 프로그램을 개발 중입니다. 그것에 대해 검색했습니다. 나는 다음 링크를 가지고있다. https://code.google.com/p/gdata-objectivec-client/Picasa 앨범에서 사진을 가져 오는 방법은 무엇입니까?

나는 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; 
} 

하지만이 코드는 매우 혼란 스럽습니다.

누구든지 도움을 줄 수 있습니다. 사진 가져 오기 코드를 시작하는 방법?

미리 감사드립니다.

답변

0

이 문제를 해결했습니다. 나는 두 가지 변화를 일으켰다. 1. loadPhotoGallery 메서드 편집 2. 사진을 가져 와서 눈금에 표시 할 새 메서드를 만듭니다.

loadPhotoGallery의 코드는 다음과 같습니다.

- (void) loadPhotoGallery{ 
    NSLog(@"fetchAllPhotos"); 
    GDataServiceGooglePhotos *service = [self photoService]; 
    GDataServiceTicket *ticket; 
NSURL *feedURL = [GDataServiceGooglePhotos photoFeedURLForUserID:@"[email protected]" 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)]; 
} 
관련 문제