【问题标题】:Facebook Share video Exception "ShareVideo must reference a video that is on the device" on AndroidAndroid 上的 Facebook 分享视频异常“ShareVideo 必须引用设备上的视频”
【发布时间】:2015-10-02 10:39:24
【问题描述】:

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

在根据Sharing on Facebook guidenline 配置 facebook 后,我尝试从移动目录上传视频,但在调用 shareddialog.show 后出现异常“ShareVideo 必须引用设备上的视频”。 `onError(FacebookException exception) 上的回调会向我报告该异常。

/**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
                    }
                }

【问题讨论】:

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


    【解决方案1】:

    这里抛出异常: 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);

    【讨论】:

    • 你的答案是完美的,代码的变化来自这个“Uri videoFileUri = Uri.parse(video.getPath());”到“Uri videoFileUri = Uri.fromFile(video);”
    猜你喜欢
    • 2015-10-18
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多