如何在Facebook上上传/分享视频? [英] How to upload/share video on Facebook ?

查看:884
本文介绍了如何在Facebook上上传/分享视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个测试应用程序,我想在Facebook上发布视频。我正在使用Facebook的最新sdk。但是我不能在Facebook上发布。



我的代码如下。

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

FBRequest * request = [FBRequest requestWithGraphPath:@me / videos参数:参数HTTPMethod:@POST];

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

请帮我通过我的应用在Facebook上发布视频。

解决方案

您需要首先下载FacebookSDK
,然后在项目中添加以下框架


  FacebookSDK.framework,FBSDKLoginKit.framework,FBSDKShareKit.framework,
Bolts.framework,FBSDKCoreKit.framework
/ pre>

导入他们,
并写入followin代码

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

[login1 logInWithPublishPermissions:@ [@publish_actions]处理程序:^(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];




}

视频网址videoURL必须是资产网址。您可以获取视频资产网址,例如从UIImagePickerController。



或录制视频,您可以如下

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

videoAssetURL = assetURL;

}];

有关更多详细信息,您可以使用 https://developers.facebook.com/docs/sharing/ios


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.

解决方案

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

这篇关于如何在Facebook上上传/分享视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆