Context
Before you can post to Facebook, you must have permission to publish (post) using either the built-in integration or the SDK for Facebook. The rule is that you must first get read permissions before write permissions.
Thus, make sure that before attempting to download the video you should have requested basic information (for example, email), and then, after that, you can request write permissions. The permission required to download the video is publish_stream .
Using iOS 6 Native Integration
Using the integrated iOS 6 integration of Facebook, you should use requestForServiceType:requestMethod:URL:parameters: SLRequest method as follows:
- (void)upload{ NSURL *videourl = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"]; NSString *filePath = [[NSBundle mainBundle] pathForResource:@"me" ofType:@"mov"]; NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO]; NSData *videoData = [NSData dataWithContentsOfFile:filePath]; NSDictionary *params = @{ @"title": @"Me being silly", @"description": @"Me testing the video upload to Facebook with the new system." }; SLRequest *uploadRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:videourl parameters:params]; [uploadRequest addMultipartData:videoData withName:@"source" type:@"video/quicktime" filename:[pathURL absoluteString]]; uploadRequest.account = self.facebookAccount; [uploadRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; if(error){ NSLog(@"Error %@", error.localizedDescription); }else NSLog(@"%@", responseString); }]; }
It is important to note here that the video data is not included in the parameter dictionary; it must be added to the SLRequest object using the addMultipartData:withName:type:filename: method.
Also note that the file name is very important when adding video data. Here I just use the full path to the file.
Using the Facebook SDK 3.1 Library
If you must support iOS versions earlier than iOS 6, or you want to use the Facebook SDK 3.1 for any other reason, the video download is a little different.
You must use the FBRequest object and NSDictionary containing the video information. The method I recommend to use is requestWithGraphPath:parameters:HTTPMethod: I used this method from my preference, although you can use some other methods to create your request object.
The following code works with the Facebook SDK 3.1 to upload videos:
- (void)upload{ if (FBSession.activeSession.isOpen) { NSString *filePath = [[NSBundle mainBundle] pathForResource:@"me" ofType:@"mov"]; NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO]; NSData *videoData = [NSData dataWithContentsOfFile:filePath]; NSDictionary *videoObject = @{ @"title": @"FB SDK 3.1", @"description": @"hello there !", [pathURL absoluteString]: videoData }; FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos" parameters:videoObject HTTPMethod:@"POST"]; [uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (!error) NSLog(@"Done: %@", result); else NSLog(@"Error: %@", error.localizedDescription); }]; } }
Here, as you can see, we add the video data to the parameters dictionary, unlike the previous solution, there along with title and description (which are 2 optional parameters). Also note that there is no source key here, as indicated in the documentation for Facebook. The key name is the name of the video file. I do not know why this should not be source , but using the source leads to com.facebook.sdk 5 error.
The error that I mentioned, which I wrote on Facebook, you can see this report on this link - if I am not mistaken in my interpretation of the documentation. Try this error and let me know if you can reproduce it. Thanks!