我第一次与Oauth合作,并与YouTube One一起玩。我得到以下代码:
if(isset($_GET['code'])) {
$code = $_GET['code'];
$url = 'https://accounts.google.com/o/oauth2/token';
$params = array(
"code" => $code,
"client_id" => "XXX",
"client_secret" => "YYY",
"redirect_uri" => "URL",
"grant_type" => "authorization_code"
);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
curl_close($curl);
$authObj = json_decode($json_response);
echo "access_token: " . $authObj->access_token;
echo "token_type: " . $authObj->token_type;
echo "expires_in: " . $authObj->expires_in;
echo "refresh_token: " . $authObj->refresh_token;
$msg = '<p class="bg-success msg-padding"><b>Success:</b> You have successfully linked your Youtube account.</p>';
}
if(isset($_GET['error'])) {
$msg = '<p class="bg-danger msg-padding"><b>Error:</b> You have canceled the Youtube account linking process.</p>';
}
如果可能的话,我如何获得YouTube频道ID,用户名,订户计数等等?
您可以使用此访问令牌通过将Mine = True作为参数来访问数据API V3中的其他数据端点。有关更多信息频道列表端点,请查看文档:https://developers.google.com/youtube/v3/docs/channels/list/list