首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Facebook共享视频异常"ShareVideo必须引用设备上的视频“

Facebook共享视频异常"ShareVideo必须引用设备上的视频“
EN

Stack Overflow用户
提问于 2015-10-02 10:39:24
回答 1查看 711关注 0票数 3

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

在根据分享Facebook指南配置facebook之后,我正在尝试从移动目录上传视频,但在sharedialog.show调用之后,我得到了例外:"ShareVideo必须引用设备上的视频“。该异常是通过回调‘`onError(FacebookException异常)向我报告的。

代码语言:javascript
复制
/**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
                    }
                }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-18 15:04:15

异常在这里抛出:https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/share/internal/ShareContentValidation.java

代码语言:javascript
复制
 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())); 
}

如您所见,正在检查uri是否有一个方案。在您的示例中,当您从video.getPath创建uri时,方案为null。您应该做的是从视频文件中创建uri:

Uri videoFileUri =Uri.fromFile(视频);

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32905407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档