2016-11-18 13 views
0

おはよう、
私のYouTubeチャンネルが所有するプライベートプレイリスト(および関連する動画)は、「サーバー間のOAuth 2.0」 ";
でも、公開されている要素のみが表示されます。
これは私のPHPコードです:Google OAuth 2.0 for PHPとサーバーのYoutubeプライベートプレイリスト

$client = new Google_Client(); 
$client->setAuthConfig(__DIR__ . "/my_service_account.json"); 
$client->setScopes('https://www.googleapis.com/auth/youtube'); 
$client->setApplicationName("NameOfMyApp"); 
$client->refreshTokenWithAssertion(); 
$token = $client->getAccessToken(); 
$accessToken = $token['access_token']; 
//--------- 
$YOUTUBE = new Google_Service_YouTube($client); 
//--------- 
$arr_opt = array('channelId' => $MY_CHANNEL_ID); 
$arr_playlist = $YOUTUBE->playlists->listPlaylists('snippet,contentDetails',$arr_opt); 
var_export($arr_playlist); 

私は「正しい」オブジェクト、 を取得するが、私のプレイリストは「プライベート」フィールド「modelData」に設定されている場合は何のアイテムを持っていない:

'modelData' => 
array (
    'pageInfo' => 
    array (
    'totalResults' => 0, 
    'resultsPerPage' => 5, 
    ), 
    'items' => 
    array (
    ), 
), 

私は何かを忘れた?
Youtube APIの制限はありますか?
私のconsole.developers.google.comでサービスアカウントの設定が正しくありませんか?

ありがとうございました!

答えて

0

この場合、PlaylistItems: listを使用することができます。それはあなたのために、より多くの情報を持つすべてのデータを取得する必要があります。次のように

また、あなたのコードでは、なります:

if ($client->getAccessToken()) { 
    try { 
    // Call the channels.list method to retrieve information about the 
    // currently authenticated user's channel. 
    $channelsResponse = $YOUTUBE->channels->listChannels('contentDetails', array(
     'mine' => 'true', 
    )); 

    $htmlBody = ''; 
    foreach ($channelsResponse['items'] as $channel) { 
     // Extract the unique playlist ID that identifies the list of videos 
     // uploaded to the channel, and then call the playlistItems.list method 
     // to retrieve that list. 
     $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_Service_Exception $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())); 
    } 
関連する問題