3

我正在Facebook Android sdk 4.6.0通过 Gradle 使用。

在根据Facebook 上的分享指南配置 facebook 后,我尝试从移动目录上传视频,但在调用 sharedialog.show 后出现异常“ShareVideo 必须引用设备上的视频”。通过 onError(FacebookException 异常)上的回调向我报告异常。

/**first checking if file exist than execute code, file exits and code execute but after executing callback with exception "Share Video must reference a video that is on the device" occurs
 **/      private void shareOnFacebook() {
                    File dir = new File(Environment.getExternalStorageDirectory(),
                            "directory");
                    File video = new File(dir, "Video.mp4");
                    if (video.exists()) {//if video file exist
                        Uri videoFileUri = Uri.parse(video.getPath());
                        ShareVideo sv = new ShareVideo.Builder()
                                .setLocalUrl(videoFileUri)
                                .build();
                        ShareVideoContent content = new ShareVideoContent.Builder()
                                .setVideo(sv)
                                .build();
                        shareDialog.show(content); //show facebook sharing screen with video
                    }
                }
4

1 回答 1

9

此处抛出异常: https ://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/share/internal/ShareContentValidation.java ;

 if (!Utility.isContentUri(localUri) && !Utility.isFileUri(localUri)) {
throw new FacebookException("ShareVideo must reference a video that is on the device");}

public static boolean isContentUri(final Uri uri) {
return (uri != null) && ("content".equalsIgnoreCase(uri.getScheme()));
}

public static boolean isFileUri(final Uri uri) {
return (uri != null) && ("file".equalsIgnoreCase(uri.getScheme())); 
}

如您所见,fb share sdk 正在检查 uri 是否有方案。在您的情况下,当您从 video.getPath 创建 uri 时,方案为空。您应该做的是从视频文件创建 uri:

Uri videoFileUri = Uri.fromFile(video);

于 2015-10-18T15:04:15.383 回答