我正在使用Flickr库从我的iPhone应用程序将照片上传到ObjectiveFlickr。我可以授权应用程序并执行一般请求,但我在尝试上传照片时遇到错误。要上传的照片是使用AVFoundation捕获的图像。相关代码如下:
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");在与上述代码相关的.h文件中定义和@property'd flickrRequest对象。
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.)"在接口文档中,error2147418115被定义为OFFlickrAPIRequestFaultyXMLResponseError。不过,我不太确定这是什么意思。同样奇怪的是,当我只尝试上传一张照片时,“成功”会出现四次。
使用ObjectiveFlickr的示例应用程序"Snap and Run“在我正在测试的同一设备上可以很好地上传照片。将我的应用程序与Snap和Run之间的代码进行比较,我没有看到任何可能导致照片无法上传的主要差异。
任何帮助都将不胜感激。
发布于 2012-04-26 00:19:12
这很奇怪。OFFlickrAPIRequestFaultyXMLResponseError表示返回的数据不能解析为XML。如果示例应用程序SnapAndRun运行正常,而您的应用程序运行不正常,我建议在ObjectiveFlickr.m中添加一行,紧跟在NSString *stat = [rsp objectForKey:@"stat"];行之后
NSString *dataString = [[[NSString alloc] initWithData:[request receivedData] encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"received response: %@", dataString);这可能会帮助你找出哪里出了问题(例如,如果是服务器端的问题,或者是库遗漏的某种响应格式)。
发布于 2013-01-20 11:54:07
当我收到这个错误时,我使用Charles来查看发生了什么。Flickr发回了一个错误,说签名是无效的。查看我的请求,我发现我颠倒了键和值的顺序(即,我的一个键中有空格,这可能会导致签名错误)。
https://stackoverflow.com/questions/9691566
复制相似问题