使用facebook sdk4.0从ios app在Facebook上分享视频

时间:2015-05-13 13:50:15

标签: ios objective-c facebook facebook-graph-api

在我的iOS移动应用中,我需要在Facebook帐户上分享/上传视频(来自照片库或使用相机拍摄)。我正在使用iOS 8.0& FacebookSDK 4.0。我尝试了很多代码,但其中任何代码都无法正常工作。我已成功完成以下步骤。 1)使用' publish_action'登录Facebook允许 2)用户在FBSDKAccessToken中确实有一个有效的访问令牌 正如官方FB文件中提到的,我已经完成了这个

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSURL * selectedVideoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
[self dismissViewControllerAnimated:picker completion:nil];

FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.videoURL = selectedVideoUrl;
FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init];
content.video = video; 
//here now i have tried both the techniques mentioned below  
}

现在我尝试使用FBSDKShareDialog发布此内容,但它不起作用&抛出错误,我也试过像这样使用FBSDKShareAPI

FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.delegate=self;
dialog.fromViewController = self;
dialog.shareContent=content;
[dialog show];

并且喜欢这个

FBSDKShareAPI *shareRequest= [FBSDKShareAPI shareWithContent:content delegate:self];
if ([shareRequest canShare]) {
    BOOL isSuccess=[shareRequest share];
    if (isSuccess) {
        NSLog(@"shared");
    }
}

如何让这个上传工作?

1 个答案:

答案 0 :(得分:2)

使用UIImagePickerControllerReferenceURL获取资产库网址而不是UIImagePickerControllerMediaURL