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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度