https://graph-video.facebook.com/上传后重定向

时间:2012-07-20 10:52:03

标签: php facebook facebook-graph-api video

我使用以下代码成功上传视频,但上传后显示一些ID页面。任何人都可以帮助您在成功上传视频后将页面重定向到我想要的位置。

提前致谢。

$app_id = "YOUR_APP_ID";
$app_secret = "YOUR_APP_SECRET";
$my_url = "YOUR_POST_LOGIN_URL";
$video_title = "TITLE FOR THE VIDEO";
$video_desc = "DESCRIPTION FOR THE VIDEO";
$page_id = "YOUR_PAGE_ID";

$code = $_REQUEST["code"];

echo '<html><body>';

if(empty($code)) {
    // Get permission from the user to publish to their page.
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
        . $app_id . "&redirect_uri=" . urlencode($my_url)
        . "&scope=publish_stream,manage_pages";
    echo('<script>top.location.href="' . $dialog_url . '";</script>');
} else {

    $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);

    $accounts_url = "https://graph.facebook.com/me/accounts?" . $access_token;
    $response = file_get_contents($accounts_url);

    $resp_obj = json_decode($response,true);
    $accounts = $resp_obj['data'];

    foreach($accounts as $account) {
        if($account['id'] == $page_id) {
            $access_token = $account['access_token'];
            break;
        }
    }

    $post_url = "https://graph-video.facebook.com/" . $page_id . "/videos?"
        . "title=" . $video_title. "&description=" . $video_desc
        . "&access_token=". $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>";
}

1 个答案:

答案 0 :(得分:0)

您必须将视频上传到Facebook,而不是访问者浏览器,因此您可以捕获输出并将访问者浏览器发送到正确的位置。

您的用户将首先在您的服务器上传文件,然后您可以使用curl将视频发送到Facebook,完成后您可以重定向用户。

实施例

  1. Facebook Graph api视频对象:http://developers.facebook.com/docs/reference/api/video/
  2. 命令行卷曲示例:http://facebook.stackoverflow.com/questions/5227607/posting-an-embedded-video-link-using-the-facebook-graph-api
  3. Facebook PHP api示例:http://facebook.stackoverflow.com/questions/9018213/video-post-on-timeline-not-playing-inline