Facebook分享视频例外“分享视频必须在Android上引用设备上的视频”

时间:2015-10-02 10:39:25

标签: android facebook facebook-sharer facebook-share facebook-exception

我通过Gradle使用Facebook Android sdk 4.6.0

我正在尝试根据Sharing on Facebook guidenline配置Facebook后从移动目录上传视频,但我得到例外情况“Sharedog.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
                    }
                }

1 个答案:

答案 0 :(得分: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时,scheme为null。你应该做的是从视频文件创建uri:

Uri videoFileUri = Uri.fromFile(video);

相关问题