4
我正在開發一個應用程序,它允許用戶上傳他們的照片到Facebook的消息。 但它不能順利運行,有時它會完美運行,並且會多次返回此錯誤。用Facebook上傳照片到Facebook的錯誤iOS SDK 3.1.1
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];
}
任何一個知道如何解決這一問題? 非常感謝你
如果這是一個正確的答案,請將其標記爲如此。謝謝! – karlofk