Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Context</h2> <p>Before you can publish onto Facebook, you must get publish (write) permissions, using either native integration or the Facebook SDK, the rule is you must first acquire read permissions before write permissions.</p> <p>Thus, make sure that before you attempt to upload a video, you should have requested basic info (email for example), then, once you have this, you can request write permissions. The permission necessary for uploading videos is <code>publish_stream</code>.</p> <h2>Using iOS 6 native Facebook integration</h2> <p>Using the native iOS 6 Facebook integration, you should use the <code>requestForServiceType:requestMethod:URL:parameters:</code> method of <code>SLRequest</code>, as follows:</p> <pre><code>- (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); }]; } </code></pre> <p>Here it's important to note that the video data does not go into the parameters dictionary, it must be added to the <code>SLRequest</code> object using the <code>addMultipartData:withName:type:filename:</code> method.</p> <p>Also note that the filename is very important when adding the videos data. Here I am just using the full path of the file.</p> <h2>Using Facebook SDK 3.1 library</h2> <p>If you must support iOS versions earlier then iOS 6 or you wish to use the Facebook SDK 3.1 for any other reason, uploading a video is a little different.</p> <p>You must use a <code>FBRequest</code> object and a <code>NSDictionary</code> that contains the videos details. The method I recommend using is <code>requestWithGraphPath:parameters:HTTPMethod:</code>, I've used this method out of preference although you should be able to use some of the other methods to create your request object.</p> <p>The following code works with Facebook SDK 3.1 to upload a video:</p> <pre><code>- (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); }]; } } </code></pre> <p>Here as you can see, we add the videos data into the <code>parameters</code> dictionary unlike the previous solution, it's there along with <code>title</code> and <code>description</code> (which are 2 optional parameters). Also note that here there is no key <code>source</code>, as specified by the Facebook documentation. The key's name is the filename of the video. I don't know why this shouldn't be <code>source</code>, but using source results in a <strong>com.facebook.sdk error 5</strong>.</p> <p>The bug I mentioned I filed with Facebook, you can see this report on <a href="https://developers.facebook.com/bugs/292307870878271" rel="noreferrer">this link</a> - unless I'm mistaken in my interpretation of the documentation. Please try out that bug and report if you can reproduce it. Thanks !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload