Android 上的 Facebook 分享视频异常 "ShareVideo must reference a video that is on the device"
Facebook Share video Exception "ShareVideo must reference a video that is on the device" on Android
我正在使用 Facebook Android sdk 4.6.0
到 Gradle。
根据 Sharing on Facebook guidenline 配置 facebook 后,我尝试从移动目录上传视频,但在调用 sharedialog.show 后出现异常 "ShareVideo must reference a video that is on the device"。通过`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
}
}
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 共享 sdk 正在检查 uri 是否有方案。
在您的情况下,当您从 video.getPath 创建 uri 时,方案为空。你应该做的是从视频文件创建 uri:
Uri videoFileUri = Uri.fromFile(视频);
我正在使用 Facebook Android sdk 4.6.0
到 Gradle。
根据 Sharing on Facebook guidenline 配置 facebook 后,我尝试从移动目录上传视频,但在调用 sharedialog.show 后出现异常 "ShareVideo must reference a video that is on the device"。通过`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
}
}
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 共享 sdk 正在检查 uri 是否有方案。 在您的情况下,当您从 video.getPath 创建 uri 时,方案为空。你应该做的是从视频文件创建 uri:
Uri videoFileUri = Uri.fromFile(视频);