首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ObjectiveFlickr照片上传错误

ObjectiveFlickr照片上传错误
EN

Stack Overflow用户
提问于 2012-03-14 04:26:48
回答 2查看 1.1K关注 0票数 3

我正在使用Flickr库从我的iPhone应用程序将照片上传到ObjectiveFlickr。我可以授权应用程序并执行一般请求,但我在尝试上传照片时遇到错误。要上传的照片是使用AVFoundation捕获的图像。相关代码如下:

代码语言:javascript
复制
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方法如下:

代码语言:javascript
复制
- (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];
}

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

代码语言:javascript
复制
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之间的代码进行比较,我没有看到任何可能导致照片无法上传的主要差异。

任何帮助都将不胜感激。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-26 00:19:12

这很奇怪。OFFlickrAPIRequestFaultyXMLResponseError表示返回的数据不能解析为XML。如果示例应用程序SnapAndRun运行正常,而您的应用程序运行不正常,我建议在ObjectiveFlickr.m中添加一行,紧跟在NSString *stat = [rsp objectForKey:@"stat"];行之后

代码语言:javascript
复制
NSString *dataString = [[[NSString alloc] initWithData:[request receivedData] encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"received response: %@", dataString);

这可能会帮助你找出哪里出了问题(例如,如果是服务器端的问题,或者是库遗漏的某种响应格式)。

票数 1
EN

Stack Overflow用户

发布于 2013-01-20 11:54:07

当我收到这个错误时,我使用Charles来查看发生了什么。Flickr发回了一个错误,说签名是无效的。查看我的请求,我发现我颠倒了键和值的顺序(即,我的一个键中有空格,这可能会导致签名错误)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9691566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档