我正在开发一个应用程序,它允许用户通过消息将他们的照片上传到 Facebook。但它运行不顺利,有时它运行完美,并且多次返回此错误。
2012-10-09 21:12:41.320 TimeLapse[1724:707] Error: HTTP status code: 200
2012-10-09 21:12:41.329 TimeLapse[1724:707] Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xf352290 {com.facebook.sdk:ErrorInnerErrorKey=Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0xf351840 {NSErrorFailingURLStringKey=https://graph.facebook.com/me/photos?sdk=ios&access_token=.....&migration_bundle=fbsdk%3A20121003&message=Ghh&format=json, NSErrorFailingURLKey=https://graph.facebook.com/me/photos?sdk=ios&access_token=....&migration_bundle=fbsdk%3A20121003&message=Ghh&format=json, NSLocalizedDescription=The request timed out., NSUnderlyingError=0xf3518b0 "The request timed out."}, com.facebook.sdk:HTTPStatusCode=200}
这是我的代码
-(void)startPostPhotoToFacebook:(UIImage *)image withMessage:(NSString *)message {
NSArray *arrPermission = [NSArray arrayWithObjects:@"publish_stream", nil];
if (FBSession.activeSession.state == FBSessionStateOpen) {
NSLog(@"Session is opened already");
[self postPhotoToFacebook:image withMessage:message];
}
else {
NSLog(@"Need to open session");
[FBSession openActiveSessionWithPublishPermissions:arrPermission defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (!error) {
[self sessionStateChangedForPostPhotoToFacebook:session state:state error:error withImage:image andMessage:message];
}
else {
NSLog(@"Open active session failed");
}
}];
}
}
-(void)sessionStateChangedForPostPhotoToFacebook:(FBSession *)session state:(FBSessionState)state error:(NSError *)error withImage:(UIImage *)image andMessage:(NSString *)message {
switch (state) {
case FBSessionStateOpen: {
[self startPostPhotoToFacebook:image withMessage:message];
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
default:
break;
}
if (error) {
NSLog(@"error");
}
}
-(void)postPhotoToFacebook:(UIImage *)image withMessage:(NSString *)message {
if (message == nil) {
message = @"";
}
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:message forKey:@"message"];
[params setObject:image forKey:@"source"];
FBRequest *request = [FBRequest requestWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"];
FBRequestConnection *fbConnection = [[FBRequestConnection alloc] initWithTimeout:10];
[fbConnection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"Result: %@", result);
[myMainViewController finishPostPhotoToFacebook];
[fbConnection release];
}
else {
NSLog(@"%@", error.description);
[myMainViewController errorPostPhotoToFacebook];
[fbConnection release];
}
}];
[fbConnection start];
}
有人知道怎么修这个东西吗?非常感谢