【发布时间】:2014-07-29 23:42:01
【问题描述】:
我正在尝试使用 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>";
【问题讨论】:
标签: php youtube-api google-oauth