title: Uploading video to Facebook from iOS app using SDK 3.6 intermittently failing
body: <p>I'm using Facebook SDK 3.6 within an iOS 6.3 app to upload a video to Facebook.</p>
  
  <p>I've looked over many Stack Overflow posts about this but they are all years old and using much older Facebook SDKs.</p>
  
  <p>Sometimes it works, other times it fails with the following message:</p>
  
  <pre><code>unexpected error:Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be     completed. (com.facebook.sdk error 5.)" UserInfo=0x1e2affc0 {com.facebook.sdk:HTTPStatusCode=500, com.facebook.sdk:ParsedJSONResponseKey={
  body = {
  "error_code" = 1;
  "error_msg" = "An unknown error occurred";
  };
  code = 500;
  }, com.facebook.sdk:ErrorSessionKey=, expirationDate: 4001-01-01 00:00:00 +0000, refreshDate: 2013-07-30 10:54:22 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
  "publish_stream"
  )&gt;}
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>FBRequestConnection *_currentConnection;
  
  [FBSession.activeSession requestNewPublishPermissions:@[@"publish_stream"]
                                            defaultAudience:FBSessionDefaultAudienceOnlyMe
                                          completionHandler:^(FBSession *session, NSError *error) {
                                              if (!error) {
  
  NSError *attributesError;
  NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:url.path error:&amp;attributesError];
  
  NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
  long long fileSize = [fileSizeNumber longLongValue];
  
  NSLog(@"file size: %lld", fileSize);
  
  NSString *filename = [url lastPathComponent];
  NSLog(@"filename: %@", filename);
  NSString *mimeType = [self MIMETypeForFilename:filename
                                         defaultMIMEType:@"video/mp4"];
  
  NSLog(@"mime type: %@", mimeType);
  
  NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                         videoData, filename,
                                         mimeType, @"contentType",
                                         self.song.name, @"title",
                                         _videoDescription, @"description",
                                         nil];
  
  
  
  
          FBRequest *request = [FBRequest requestWithGraphPath:@"me/videos"
                                                    parameters:params
                                                    HTTPMethod:@"POST"];
  
  
  
          _currentConnection = [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
              [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
  
              self.stageLabel.text = @"";
  
              NSLog(@"result: %@, error: %@", result, error);
              if(error) {
                  // Facebook SDK * error handling *
                  // if the operation is not user cancelled
                  if (error.fberrorCategory != FBErrorCategoryUserCancelled) {
                      [self showAlert:@"Video Post" result:result error:error];
                  }
  
                  self.uploadBarButtonItem.enabled = YES;
              } else {
                  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Video Uploaded" message:@"Video has been uploaded"
                                                                 delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                  [alert show];
                  [self.delegate facebookUploaderUploadSucceeded:self];
              }
  
              // Delete the temp video
              NSError *err;
              [[NSFileManager defaultManager] removeItemAtURL:_sourceURL error:&amp;err];
              NSLog(@"Deleting video %@: %@", _sourceURL, [err localizedDescription]);
  
  
          }];
  
  
  
      }];
  
  }
  }];
  </code></pre>