【问题标题】:Fetch list of videos from Youtube channels using Youtube API v3 (without the annoying authentication pop-up)使用 Youtube API v3 从 Youtube 频道获取视频列表(没有烦人的身份验证弹出窗口)
【发布时间】:2014-01-26 12:32:58
【问题描述】:

我有一个 youtube 频道,我正在使用 Youtube API v3 来提取该频道中上传的视频列表(使用 php 库)。以下是我正在使用的代码的 sn-p:

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',

但是,我收到一个烦人的弹出窗口,要求我登录并进行身份验证以获取详细信息。我怎样才能摆脱这个身份验证弹出窗口? 我打算编写一个 cron 作业,它会定期提取视频列表并将其存储在数据库中,因此我不希望出现该身份验证弹出窗口。

注意:当我尝试从播放列表中提取视频时,不会要求我进行任何身份验证,并且 api 运行顺利

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

【问题讨论】:

    标签: php youtube-api


    【解决方案1】:

    是的,您不需要 OAuth2 登录。您只需设置 API 密钥即可。

    这是一个 playlistItems->列表请求。

    这里是 api explorer 中的演示:https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.playlistItems.list?part=snippet&playlistId=PLjFEz-E0UPUxw3lFpnfV1dDA7OE7YIFRj&_h=2&

    而不是设置clientId和client Secret

    在公共 API 访问中从云控制台将其 API 密钥设置为您的 API 密钥。

    $client->setAPIKey($API_KEY);

    【讨论】:

      【解决方案2】:

      您无需认证即可从 YouTube 频道获取视频列表。使用 YouTube Data API 从 YouTube 频道获取视频列表。

      $API_key    = 'Your_API_Key';
      $channelID  = 'YouTube_Channel_ID';
      $maxResults = 10;
      
      $videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$API_key.''));
      

      【讨论】:

        猜你喜欢
        • 2013-10-12
        • 2017-11-21
        • 2016-03-12
        • 2015-03-11
        • 1970-01-01
        • 2015-01-14
        • 2013-10-27
        • 2015-09-16
        • 2014-05-02
        相关资源
        最近更新 更多