Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload/share video on Facebook ?

I am making a test app through that I want to post video on facebook. I am using latest sdk of facebook. But I am not able to post it on facebook.

My code is as below.

NSDictionary *parameters = [NSDictionary dictionaryWithObject:videoData forKey:@"CareAppDemo.mov"];

FBRequest *request = [FBRequest requestWithGraphPath:@"me/videos" parameters:parameters HTTPMethod:@"POST"];

[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                NSLog(@"result: %@, error: %@", result, error);
            }];

Please help me to post video on facebook via my app.

like image 314
Hitendra Avatar asked Jan 28 '14 10:01

Hitendra


1 Answers

You need to download FacebookSDK first and then add following framework into your project

FacebookSDK.framework, FBSDKLoginKit.framework, FBSDKShareKit.framework,
Bolts.framework,FBSDKCoreKit.framework

import them, and write followin code

if(![FBSDKAccessToken currentAccessToken])
    {
        FBSDKLoginManager *login1 = [[FBSDKLoginManager alloc]init];

        [login1 logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {

            FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];

            video.videoURL = videoAssetURL;
            FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init];
            content.video = video;

            [FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];




        }];
    }
    else {
        FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
        video.videoURL = videoAssetURL;
        FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init];
        content.video = video;

        [FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];




    }

The video URL videoURL must be an asset URL. You can get a video asset URL e.g. from UIImagePickerController.

or for recording video you can take as follow

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"] stringByAppendingFormat:@"/current.mov"]] completionBlock:^(NSURL *assetURL, NSError *error)
 {

     videoAssetURL =assetURL;

 }];

for more detail you can use https://developers.facebook.com/docs/sharing/ios

like image 70
Jaydeep Patel Avatar answered Sep 26 '22 04:09

Jaydeep Patel