Facebook图片上传有效但Facebook视频上传失败

时间:2013-05-30 19:33:36

标签: facebook image video upload unity3d

我正在努力进行Facebook视频上传。 获取令牌后实现代码时出现的错误是400错误请求。

我可以登录并获得令牌。 我为Facebook应用设置了应允许视频上传的权限,并检查了这些权限是否正确。 我也可以使用相同的方法发布图像,但出于某种原因发布视频失败,出现400错误。

以下代码来自Unity3d。下面的代码基本上执行POST并将视频数据添加到帖子中。就像我说它适用于图像文件但不适用于视频。

    private WWW w;
    public void FBPostVideo(){
    Debug.Log("in the fbpostvideo ienumerator");
    var moviebytes = System.IO.File.ReadAllBytes(Application.persistentDataPath+"/screenrecording.mp4");
    Debug.Log(moviebytes.Length);
    WWWForm form = new WWWForm();
    var video_desc="walkingthedog";
    var video_title="dogwalk";
    var access_token=token;
    form.AddBinaryData("file", moviebytes, "myvideo");
    var formurl="https://graph-video.facebook.com/me/videos?title="+video_title
+ "&description=" +video_desc + "&"+token;
    Debug.Log(formurl);
    WWW w = new WWW(formurl, form);
    StartCoroutine(waitForMovie(w));
    }

    public IEnumerator waitForMovie(WWW w){
    yield return w;
    if (!String.IsNullOrEmpty(w.error))
    Debug.Log(w.error);
    else
    Debug.Log("Finished Uploading");
    }

    *

    *The php suggested code:
    <?php
    $app_id = "YOUR_APP_ID";
    $app_secret = "YOUR_APP_SECRET";
    $my_url = "YOUR_POST_LOGIN_URL";
    $video_title = "YOUR_VIDEO_TITLE";
    $video_desc = "YOUR_VIDEO_DESCRIPTION";

    $code = $_REQUEST["code"];

    if(empty($code)) {
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
    . $app_id . "&redirect_uri=" . urlencode($my_url)
    . "&scope=publish_stream";
    echo("<script>top.location.href='" . $dialog_url . "'</script>");
    }

    $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
    . $app_id . "&redirect_uri=" . urlencode($my_url)
    . "&client_secret=" . $app_secret
    . "&code=" . $code;
    $access_token = file_get_contents($token_url);

    $post_url = "https://graph-video.facebook.com/me/videos?"
    . "title=" . $video_title. "&description=" . $video_desc
    . "&". $access_token;

    echo '<form enctype="multipart/form-data" action=" '.$post_url.' "
    method="POST">';
    echo 'Please choose a file:';
    echo '<input name="file" type="file">';
    echo '<input type="submit" value="Upload" />';
    echo '</form>';
    ?>*

0 个答案:

没有答案