2014-01-26 44 views
0

好家伙我使用YouTube API V3,得到了下面的命令:如何显示只从我的帐户的影片 - YouTube API V3

我有我的帐户私密视频,一些网友在我的系统logarão对于网络注销谷歌,但当这个用户登录我的系统时,它会通过youtube API显示我的帐户上的私人视频。

问题是,捕获api列出的视频的例子是在那一刻登录的人,这不是我想要的。

我后面的的例子是,:

<?php 
// Call set_include_path() as needed to point to your client library. 
require_once 'Google_Client.php'; 
require_once 'contrib/Google_YoutubeService.php'; 
session_start(); 

/* You can acquire an OAuth 2 ID/secret pair from the API Access tab on the Google APIs Console 
    <http://code.google.com/apis/console#access> 
For more information about using OAuth2 to access Google APIs, please visit: 
    <https://developers.google.com/accounts/docs/OAuth2> 
Please ensure that you have enabled the YouTube Data API for your project. */ 
$OAUTH2_CLIENT_ID = 'REPLACE_ME'; 
$OAUTH2_CLIENT_SECRET = 'REPLACE_ME'; 

$client = new Google_Client(); 
$client->setClientId($OAUTH2_CLIENT_ID); 
$client->setClientSecret($OAUTH2_CLIENT_SECRET); 
$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], 
    FILTER_SANITIZE_URL); 
$client->setRedirectUri($redirect); 

$youtube = new Google_YoutubeService($client); 

if (isset($_GET['code'])) { 
    if (strval($_SESSION['state']) !== strval($_GET['state'])) { 
    die('The session state did not match.'); 
    } 

    $client->authenticate(); 
    $_SESSION['token'] = $client->getAccessToken(); 
    header('Location: ' . $redirect); 
} 

if (isset($_SESSION['token'])) { 
    $client->setAccessToken($_SESSION['token']); 
} 

if ($client->getAccessToken()) { 
    try { 
    $channelsResponse = $youtube->channels->listChannels('contentDetails', array(
     'mine' => 'true', 
    )); 

    $htmlBody = ''; 
    foreach ($channelsResponse['items'] as $channel) { 
     $uploadsListId = $channel['contentDetails']['relatedPlaylists']['uploads']; 

     $playlistItemsResponse = $youtube->playlistItems->listPlaylistItems('snippet', array(
     'playlistId' => $uploadsListId, 
     'maxResults' => 50 
    )); 

     $htmlBody .= "<h3>Videos in list $uploadsListId</h3><ul>"; 
     foreach ($playlistItemsResponse['items'] as $playlistItem) { 
     $htmlBody .= sprintf('<li>%s (%s)</li>', $playlistItem['snippet']['title'], 
      $playlistItem['snippet']['resourceId']['videoId']); 
     } 
     $htmlBody .= '</ul>'; 
    } 
    } catch (Google_ServiceException $e) { 
    $htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>', 
     htmlspecialchars($e->getMessage())); 
    } catch (Google_Exception $e) { 
    $htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>', 
     htmlspecialchars($e->getMessage())); 
    } 

    $_SESSION['token'] = $client->getAccessToken(); 
} else { 
    $state = mt_rand(); 
    $client->setState($state); 
    $_SESSION['state'] = $state; 

    $authUrl = $client->createAuthUrl(); 
    $htmlBody = <<<END 
    <h3>Authorization Required</h3> 
    <p>You need to <a href="$authUrl">authorize access</a> before proceeding.<p> 
END; 
} 
?> 

<!doctype html> 
<html> 
    <head> 
    <title>YouTube Search</title> 
    </head> 
    <body> 
    <?=$htmlBody?> 
    </body> 
</html> 

那么如何在atentique quue API使用单一账户,并把视频这个帐户,而不是与有问题的用户帐户authenticating吗?


原始

奥拉pessoal欧盟我在这山岛一个API做的YouTube呐V3ËtenhoØseguinte intuito:

Tenho影片privados呐明哈CONTA,alguns USUARIOS SElogarão没有MEU SISTEMA网络陈健波庵登录论坛谷歌搜索使用条款和条件隐私权政策网站反馈网站反馈网站反馈网站反馈请您登录或注册本网站使用cookies。

Oproblemaéque com os exemplos que peguei da api osvídeosquesãolistados vem da pessoa queestálogada naquele momento enãoéiso o que quero。

Øexemplo阙我在这seguindoéeste

Então科莫FAZER对阙一个API本身atentique COM UMA CONTA UNICAËtraga OS视频德斯塔CONTA AO INVES德autenticar COM一个CONTA做usuárioEMquestão?

回答

-1

点击你的YouTube视频。视频下方将显示电子邮件代码。粘贴到您想要显示的网页中。

+0

没有解决这个朋友,我真正想要的是从一个帐户带来私人视频,尤其是访问系统的用户。 私有视频可能不是简单嵌入或iframe的一部分 – deFreitas

相关问题