如何获得频道id或url后谷歌Oauth PHP


How to Get Channel id or url after Google Oauth PHP

我正试图编码一个应用程序系统与YouTube登录。但我有一个问题后,我得到所需的授权与oauth 2.0我想得到选择的youtube频道id在一个字符串,但我不能这样做,有人可以请帮助我。

    $client = new Google_Client();
    $client->setClientId($client_id);
    $client->setClientSecret($client_secret);
    $client->setRedirectUri($redirect_uri);
    $client->setApplicationName("BYTNETWORK");
    $client->setScopes(array('https://www.googleapis.com/auth/userinfo.profile',
     'https://www.googleapis.com/auth/yt-analytics.readonly' 
      ));
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
  $client->setAccessToken($_SESSION['access_token']);
} else {
  $authUrl = $client->createAuthUrl();
}

之后我想要一个像

这样的字符串

$channelid = "xxxxx";在

下面的代码中使用它
$data = file_get_contents('http://gdata.youtube.com/feeds/api/users/$channelid?alt=json');
$data = json_decode($data, true);
$stats_data = $data['entry']['yt$statistics'];
$medya = $data['entry']['media$thumbnail'];
//yt$username kısmından kanal adı parse edilir
/**********************************************************/
echo "<img src='$medya[url]'></img><br>";
echo "Subscribers: $stats_data[subscriberCount]<br>";
echo "Views: $stats_data[totalUploadViews]<br>";

使用OAUTH 2,您可以为请求的范围获得一个refresh_token和一个access_token。如果您想使用授权用户的access_token获取其YouTube频道id,则发送请求:

https://www.googleapis.com/youtube/v3/channels?part=id&mine=true&access_token=HereYourAccessToken

在上面的请求中,您需要替换字符串"HereYourAccessToken"。响应是一个JSON字符串。通道id在名为:items['id'](或items.id)的字段中。

注意,access_token在1小时后过期。如果是,那么使用refresh_token来获取一个新的;