2012-03-13 2 views
3

ObjectiveFlickr 라이브러리를 사용하여 내 iPhone 앱에서 Flickr에 사진을 업로드하고 있습니다. 앱을 승인하고 일반적인 요청을 수행 할 수는 있지만 사진을 업로드하는 중에 오류가 발생합니다. 업로드 할 사진은 AVFoundation을 사용하여 캡처 한 이미지입니다.ObjectiveFlickr 사진 업로드 오류

UIImage *image = [[UIImage alloc] initWithData:imageData]; 
if ([[AppDelegate sharedDelegate].apiContext.OAuthToken length]) { 
        NSData *uploadData = UIImageJPEGRepresentation(image, 1); 

        if (!flickrRequest) { 
         flickrRequest = [[OFFlickrAPIRequest alloc] initWithAPIContext:[AppDelegate sharedDelegate].apiContext]; 
         flickrRequest.delegate = self; 
         flickrRequest.requestTimeoutInterval = 60.0; 
        } 

        [flickrRequest uploadImageStream:[NSInputStream inputStreamWithData:uploadData] suggestedFilename:@"Test" MIMEType:@"image/jpeg" arguments:[NSDictionary dictionaryWithObjectsAndKeys:@"0", @"is_public", nil]]; 
        [UIApplication sharedApplication].idleTimerDisabled = YES; 

        NSLog(@"Can upload photo"); 

flickrRequest 개체 정의되고 @property 상기 코드에 속하는 .H 파일 거라고 다음은 관련 코드이다. 내가 장치에 프로젝트를 실행하면

- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest imageUploadSentBytes:(NSUInteger)inSentBytes totalBytes:(NSUInteger)inTotalBytes { 
    NSLog(@"Success"); 
} 

- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary { 
    NSLog(@"%s %@ %@", __PRETTY_FUNCTION__, inRequest.sessionInfo, inResponseDictionary); 
} 

- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didFailWithError:(NSError *)inError { 
    NSLog(@"%s %@ %@", __PRETTY_FUNCTION__, inRequest.sessionInfo, inError); 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[inError description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
    [alert show]; 
} 

콘솔을 보여줍니다 다음과 같이

OFFlickrRequestDelegate 방법

Can upload photo 
Success 
Success 
Success 
Success 
flickrAPIRequest:didFailWithError:(null) Error Domain=org.lukhnos.ObjectiveFlickr Code=2147418115 "The operation couldn’t be completed. (org.lukhnos.ObjectiveFlickr error 2147418115.)" 

API의 문서 "오류 2147418115"을 통해 검색으로 정의된다 "OFFlickrAPIRequestFaultyXMLResponseError". 나는 이것이 무엇을 의미하는지 정말로 모르겠다. 또한 이상한 - "성공"은 사진 한 장만 업로드하려고 할 때 네 번 나타납니다.

ObjectiveFlickr의 "Snap and Run"을 사용하는 샘플 앱은 테스트 할 때 동일한 장치에서 사진을 업로드합니다. 내 앱과 Snap and Run 사이의 코드를 비교하면 사진을 업로드하지 못하게하는 주요 차이점이 보이지 않습니다.

도움을 주시면 감사하겠습니다.

답변

1

이상합니다. OFFlickrAPIRequestFaultyXMLResponseError은 반환 된 데이터를 XML로 파싱 할 수 없음을 의미합니다. 샘플 응용 프로그램 SnapAndRun가 제대로 실행하고 당신이, 내가 바로 선 NSString *stat = [rsp objectForKey:@"stat"]; 후, ObjectiveFlickr.m에 한 줄을 추가 제안하지 않는 경우 : 그것이 만약

NSString *dataString = [[[NSString alloc] initWithData:[request receivedData] encoding:NSUTF8StringEncoding] autorelease]; 
NSLog(@"received response: %@", dataString); 

이것은 당신이 (무엇이 잘못되었는지 등을 찾는 데 도움이 될 수 있습니다 서버 측 문제 또는 라이브러리가 놓친 응답 형식).

1

이 오류가 발생했을 때 나는 무슨 일이 있었는지 확인하기 위해 Charles을 사용했습니다. Flickr는 서명이 유효하지 않다는 오류를 다시 보냈습니다. 요청을 보면 키와 값의 순서가 바뀌 었음을 발견했습니다 (즉, 키에 공백이있어 서명 오류가 발생했을 수 있음).