0

我正在尝试使用批处理请求在 Fb 中发布不止一张照片的帖子,但我不断收到来自 Fb 服务器的超时错误...

这是我的代码..

UIImage *imgFile1 = [UIImage imageNamed:@"iTGps.png"]; NSData *imageData = UIImageJPEGRepresentation(imgFile1, 0.5);

NSString *jsP1 = [NSString stringWithFormat:@"{ \"method\": \"POST\", \"relative_url\": \"me/photos\",\"body\":\"message=My cat photo\",\"attached_files\":\"%@\"}",imageData];

NSString *jsonRequestsArray = [NSString stringWithFormat:@"[%@,%@,%@]",jsP1,jsP1,jsP1];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:jsonRequestsArray forKey:@"batch"];

FBRequestConnection *connect = [[FBRequestConnection alloc] initWithTimeout:60];

// do Fb request
FBRequest *request = [FBRequest requestWithGraphPath:@"me/photos"
                                      parameters:params
                                      HTTPMethod:@"POST"];

// add connection
[connect addRequest:request
  completionHandler:^(FBRequestConnection *connection,
                  id result,
                      NSError *error) {

      NSLog(@"Result:%@,%@",result,error);

  }];

[connect start];

我哪里做错了??

错误代码很长,所以我剪掉了中间部分(我认为是二进制图像)

2013-04-28 20:03:32.435 trueGps[1887:1a603] 结果:(null),Error Domain=com.facebook.sdk Code=5“操作无法完成。(com.facebook.sdk错误5 .)" UserInfo=0x14454010 {com.facebook.sdk:ErrorInnerErrorKey=Error Domain=NSURLErrorDomain Code=-1001 "请求超时。" UserInfo=0x14492d40 {NSErrorFailingURLStringKey= https://graph.facebook.com/me/photos?sdk=ios&batch=%5B%7B%20%22method%22%3A%20%22POST%22%2C%20%22relative_url%22 %3A%20%22me%2Fphotos%22%2C%22body%22%3A%22message%3DMy%20cat%20photo%22%2C%22attached_files ....

NSLocalizedDescription=请求超时。, NSUnderlyingError=0x2a90f620 "请求超时。"}, com.facebook.sdk:HTTPStatusCode=200}

4

1 回答 1

0

我解决了这个问题..但仍然有更多帖子,每个帖子中只有一张照片..

NSString *rel_url = [NSString stringWithFormat:@"%@/photos",nomeAlbum];

NSString *jsP1 = [NSString stringWithFormat:@"{ \"method\": \"POST\", \"relative_url\": \"%@\", \"body\": \"message=My_cat_photo\", \"attached_files\": \"file1\" }",rel_url];

NSString *jsonRequestsArray = [NSString stringWithFormat:@"[%@]",jsP1];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:jsonRequestsArray forKey:@"batch"];

[params setObject:imgFile1 forKey:@"file1"];

[FBRequestConnection startWithGraphPath:rel_url
                             parameters:postParams
                             HTTPMethod:@"POST"
                            completionHandler:^(FBRequestConnection *connection,
                                                id result,
                                                NSError *error) {
                            }];
于 2013-04-30T08:28:36.437 回答