2013-04-01 2 views
2

GMail 연락처 (친구 목록)를 가져 오려고합니다. 친구의 메일 ID, 이름 및 전화 번호가 있지만 이미지를 얻으려고하면 "401 오류"라고 표시됩니다.Gmail 주소록에서 친구 프로필 사진을 얻는 방법은 무엇입니까?

내가 사용한 코드는 다음과 같습니다

GDataLink *photoLink = [contact photoLink]; 
NSLog(@"%@",photoLink); 

NSURL *imageURL = [photoLink URL]; 
NSLog(@"image url = %@",imageURL); 

어떻게 친구의 프로필 사진을 얻을 수 있나요? 나는 어디로 잘못 갔는가?

+0

콘솔에 로그인했을 때 일반적인 photLink URL은 어떻게 생겼습니까? –

+0

https://www.google.com/m8/feeds/photos/media/username%40gmail.com/63402b0d25e6ad 위와 같은 링크가 있습니다. – Ann

+0

사진 링크 URL을 가져 오는 다른 방법이 있습니까? – Ann

답변

1

Looking at some other (public) code that's roughly the same as what you're doing, 나는 당신이이 사진 링크 토큰 인증을 사용해야합니다 것을 알 수있다. 이 인증 토큰이 없으면 Google은 사용자가 악의적 인 것으로 판단하여 401 오류를 다시 전송합니다.

E.G.

GDataLink *photoLink = [contact photoLink]; 

    NSString *imageETag = [photoLink ETag]; 
    if (imageETag == nil || ![mContactImageETag isEqual:imageETag]) { 

     if (imageETag != nil) { 

     // get an NSURLRequest object with an auth token 
     NSURL *imageURL = [photoLink URL]; 
     GDataServiceGoogleContact *service = [self contactService]; 

     // requestForURL:ETag:httpMethod: sets the user agent header of the 
     // request and, when using ClientLogin, adds the authorization header 
     NSMutableURLRequest *request = [service requestForURL:imageURL 
                 ETag:nil 
                httpMethod:nil]; 

     [request setValue:@"image/*" forHTTPHeaderField:@"Accept"]; 

     GTMHTTPFetcher *fetcher = [GTMHTTPFetcher fetcherWithRequest:request]; 
     [fetcher setAuthorizer:[service authorizer]]; 
     [fetcher beginFetchWithDelegate:self 
       didFinishSelector:@selector(imageFetcher:finishedWithData:error:)]; 
     } 
    } 
    } 
+0

를 공유하시기 바랍니다 수있는 가능한 경우 - (GDataServiceGoogleContact *) ContactService에서 { 정적 GDataServiceGoogleContact * 서비스 = 전무 가져 오기 방법은 은 '입니다 ; if (! service) { service = [[GDataServiceGoogleContact alloc] init]; [service setShouldCacheResponseData : YES]; [service setServiceShouldFollowNextLinks : YES]; [service setAuthorizer : @ "My Access Token"]; } 반품 서비스; } – Ann

관련 문제