ios - 如何在 Facebook 上传/分享视频?

标签 ios iphone facebook-graph-api

我正在制作一个测试应用程序,我想通过它在 facebook 上发布视频。我正在使用 facebook 的最新 sdk。但我无法将其发布到 Facebook。

我的代码如下。

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);
            }];

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

最佳答案

您需要先下载FacebookSDK 然后将以下框架添加到您的项目中

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

导入它们, 并编写以下代码

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];




    }

视频 URL videoURL 必须是 Assets URL。您可以获得视频 Assets URL,例如来自 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

关于ios - 如何在 Facebook 上传/分享视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21402660/

相关文章:

iphone - 自定义字体在我的应用程序中不起作用?

iphone - 调用 graph api Facebook ios 时 facebookErrDomain 错误 10000

php - 图返回错误 : Can't Load URL: The domain of this URL isn't included in the app's domains

ios - 是否可以仅从 native 移动应用程序使用 Facebook 的分数和成就 API?

iOS - iFrame 中的原生滚动

ios - 如果没有可用值,从字符串中删除 "(null)"

ios - CAGradientLayer:其他 UIObject 未显示

ios - 在表格 View 中显示下载的图像

iphone - NSUserDefaults 同步方法

Facebook API 私有(private)消息图像已过期 - 如何获取新图像? URL签名已过期