Iphone ObjectiveFlickr照片上载错误
我正在使用ObjectiveFlickr库将照片从iPhone应用程序上传到Flickr。我可以授权应用程序并执行一般请求,但我在尝试上载照片时出错。上传的照片是使用AVFoundation拍摄的图像。以下是相关代码:Iphone ObjectiveFlickr照片上载错误,iphone,ios,flickr,photo-upload,Iphone,Ios,Flickr,Photo Upload,我正在使用ObjectiveFlickr库将照片从iPhone应用程序上传到Flickr。我可以授权应用程序并执行一般请求,但我在尝试上载照片时出错。上传的照片是使用AVFoundation拍摄的图像。以下是相关代码: UIImage *image = [[UIImage alloc] initWithData:imageData]; if ([[AppDelegate sharedDelegate].apiContext.OAuthToken length]) {
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");
flickrequest
对象在与上述代码相关的.h文件中被定义和@property
'd
单击请求委托的方法如下所示:
- (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文档中搜索,“error2147418115
”定义为“offlickraprequestfaultyxmlresponseerror
”。但我不确定这意味着什么。同样奇怪的是,当我只想上传一张照片时,“成功”出现了四次
使用ObjectiveFlickr的示例应用程序“抓拍并运行”可以在我正在测试的同一台设备上很好地上传照片。通过比较我的应用程序和Snap and Run之间的代码,我没有发现任何可能导致照片无法上传的主要差异
任何帮助都将不胜感激。真奇怪OFFlickrAPIRequestFaultyXMLResponseError
表示返回的数据不能解析为XML。如果示例应用程序SnapAndRun运行正常,而您的应用程序运行不正常,我建议在ObjectiveFlickr.m中的NSString*stat=[rsp objectForKey:@“stat”]行后面添加一行代码>:
NSString *dataString = [[[NSString alloc] initWithData:[request receivedData] encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"received response: %@", dataString);
这可能有助于您找出问题所在(例如,如果是服务器端问题,或者库遗漏了某些响应格式)。当我遇到此错误时,我通常会查看发生了什么。Flickr发回一个错误,说签名无效。查看我的请求,我发现我颠倒了键和值的顺序(即,我的一个键中有空格,这可能导致签名错误)