douyuan3842 2014-01-26 12:32
浏览 120
已采纳

使用Youtube API v3从Youtube频道中获取视频列表(没有恼人的身份验证弹出窗口)

I have a youtube channel and i'm using the Youtube API v3 to pull a list of videos uploaded in that channel (using the php libraries). The following is a snippet of the code i'm using :

require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_YouTubeService.php';
session_start();

$OAUTH2_CLIENT_ID = 'xxxxxxxxx';
$OAUTH2_CLIENT_SECRET = 'xxxxxxxxx';

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

$channelsResponse = $youtube->channels->listChannels('contentDetails', array(
      'mine' => 'true',

However, i get an annoying popup that asks me to login and authenticate in order to fetch the details. How can i get rid of this authentication popup? I'm planning to write a cron job that will pull the list of videos periodically and store it in a DB so i do not want that authentication popup.

NOTE : When i try to pull videos from a playlist, i'm not asked any authentication and the api functions smoothly

$playlistItemsResponse = $youtube->playlistItems->listPlaylistItems('snippet,status', array(
          'part' => 'snippet,contentDetails',
          'maxResults' => 50,
          'playlistId' => 'UUGpAMVStIfaQ32K-vhwNIxw'
        ));
  • 写回答

2条回答 默认 最新

  • duanshan3427 2014-01-26 14:04
    关注

    Yes, you don't need OAuth2 login for that. You can simply do it by setting your API key instead.

    It's a playlistItems->list request.

    Here's demonstration in api explorer: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.playlistItems.list?part=snippet&playlistId=PLjFEz-E0UPUxw3lFpnfV1dDA7OE7YIFRj&_h=2&

    Instead of setting clientId and client Secret

    set it's API key to your API key from cloud console in Public API access.

    $client->setAPIKey($API_KEY);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab