Youtube - 使用所有者帐户通过API 'logged in'时查看私人视频



是否可以通过youtube API登录在网页上查看自己的私人视频?

因此,如果我在页面上有某种身份验证会话,我可以通过执行以下操作来播放我的私人视频:http://www.youtube.com/embed/gYD0lKSIwxY ?

这是我如何改变一个视频的状态。这允许我将私人视频更改为未列出,以便我可以从我的网站查看它。我使用一个javascript定时器和ajax改变它回到私有后,它已经开始播放。

<?php
/**
 * Change the status of a video on youtube
 */
if (isset($_POST['video_id'])) {
    $video_id = stripslashes(strip_tags($_POST['video_id']));
    $status = (isset($_POST['status'])) ? stripslashes(strip_tags($_POST['status'])) : 'private';
    $sessionToken = 'your_session_token';
    define('YT_DEVELOPER_KEY', 'your_developer_key');
    $uploadURL = $uploadToken = null;
    try {
    $hCurl = curl_init();
    if (!$hCurl)
        throw new Exception('Failed to create cURL object');
    $videoPrivate = <<<mof
        <entry xmlns='http://www.w3.org/2005/Atom'
                xmlns:media='http://search.yahoo.com/mrss/'
                xmlns:yt='http://gdata.youtube.com/schemas/2007'
                xmlns:gd='http://schemas.google.com/g/2005'
                gd:fields='media:group/yt:private'>
            <media:group>
                <yt:private/>
            </media:group>
        </entry>
mof;
    $videoUnlistedNotPrivate = <<<mof
        <entry xmlns='http://www.w3.org/2005/Atom'
            xmlns:yt='http://gdata.youtube.com/schemas/2007'
            xmlns:gd='http://schemas.google.com/g/2005'
            gd:fields='media:group(yt:private),yt:accessControl'>
          <yt:accessControl action='comment' permission='allowed'/>
          <yt:accessControl action='commentVote' permission='allowed'/>
          <yt:accessControl action='embed' permission='allowed'/>
          <yt:accessControl action='rate' permission='allowed'/>
          <yt:accessControl action='list' permission='denied'/>
          <yt:accessControl action='syndicate' permission='allowed'/>
          <yt:accessControl action='videoRespond' permission='allowed'/>
        </entry>
mof;
    // send email for testing purposes
    if ($status == 'private') {
        mail('test@local.dev', 'VI test', 'setting private', 'from: test@local.dev');
        $videoMeta = $videoPrivate;
    } else {
        $videoMeta = $videoUnlistedNotPrivate;
        mail('test@local.dev', 'VI test', 'setting unlisted', 'from: test@local.dev');
    }

    $contentLength = strlen($videoMeta);
    $respData = null;
    $url = 'http://gdata.youtube.com/feeds/api/users/YourYouTubeName/uploads/' . $video_id;
    $ops = array(
        CURLOPT_URL => $url,
        CURLOPT_POST => true,
        CURLOPT_CUSTOMREQUEST => 'PATCH',
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_MAXREDIRS => 1,
        CURLOPT_HTTPHEADER => array(
        'Authorization: AuthSub token="' . $sessionToken . '"',
        'GData-Version: 2',
        'Content-Length: ' . $contentLength,
        'Content-Type: application/xml',
        'X-GData-Key: key=' . YT_DEVELOPER_KEY,
        ),
        CURLOPT_POSTFIELDS => $videoMeta
    );
    curl_setopt_array($hCurl, $ops);
    // fetch and parse the response to get upload URL and token
    if (($respData = curl_exec($hCurl)) === false) {
        throw new Exception('cURL returned an error while uploading video metadata: ' . curl_error($hCurl));
    }
    } catch (Exception $e) {
    echo $e->getMessage();
    exit;
    }
}
?>

相关内容

  • 没有找到相关文章

最新更新