I wrote following code for uploading video to facebook from iOS device.
-(void)uploadVideo {
NSLog(@"UPload Videio ");
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"mov"];
NSLog(@"Path is %@", filePath);
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@"Video Test Title", @"title",
@"Video Test Description", @"description",
nil];
// [facebook requestWithGraphPath:@"me/videos"
// andParams:params
// andHttpMethod:@"POST"
// andDelegate:self];
if (FBSession.activeSession.isOpen) {
[FBRequestConnection startWithGraphPath:@"me/videos"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(@"OK: %@", result);
} else
NSLog(@"Error: %@", error.localizedDescription);
}];
} else {
// We don't have an active session in this app, so lets open a new
// facebook session with the appropriate permissions!
// Firstly, construct a permission array.
// you can find more "permissions strings" at http://developers.facebook.com/docs/authentication/permissions/
// In this example, we will just request a publish_stream which is required to publish status or photos.
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"publish_stream",
nil];
//[self controlStatusUsable:NO];
// OPEN Session!
[FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// if login fails for any reason, we alert
if (error) {
// show error to user.
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
// no error, so we proceed with requesting user details of current facebook session.
[FBRequestConnection startWithGraphPath:@"me/videos"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// [FBRequestConnection setVideoMode:NO];
if(!error) {
NSLog(@"VEEERRRRRRR: %@", result);
} else
NSLog(@"VVEEERRRRREEEERRR: %@", error.localizedDescription);
}];
//[self promptUserWithAccountNameForUploadPhoto];
}
// [self controlStatusUsable:YES];
}];
}
}
This gives me error The operation couldn’t be completed. (com.facebook.sdk error 5.)
I don't know what is wrong with facebook. It uploads image, text, but in video it gives this error.
NOTE:
- It is not due to send again and again, as I also tested by making new account and resetting iOS Device.
- sample.mov also exists and works with graph api, but issue is with this SDK.
Thanks.