How to upload/share video on Facebook ?

前端 未结 3 968
不知归路
不知归路 2021-02-04 20:16

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.<

3条回答
  •  一个人的身影
    2021-02-04 20:50

    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

提交回复
热议问题