2012-03-13 121 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文件。

OFFlickrRequestDelegate方法如下:

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

当我在设备上运行该项目的控制台显示:

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和Run之间的代码,我没有看到可能导致照片无法上传的任何主要差异。

任何帮助将不胜感激。

回答

1

这很奇怪。 OFFlickrAPIRequestFaultyXMLResponseError表示返回的数据不能被解析为XML。如果示例应用程序SnapAndRun运行正确,你不这样做,我建议增加一个行ObjectiveFlickr.m,行NSString *stat = [rsp objectForKey:@"stat"];之后:

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

这可能会帮助你找出什么出错(例如,如果它是一个服务器端问题,或者库缺失的一些响应格式)。

1

当我得到这个错误,我用Charles看看发生了什么。 Flickr发回一个错误,表示签名无效。看着我的请求,我发现我已经颠倒了键和值的顺序(即我的一个键中有空白,这可能导致了签名错误)。