0
我已经通过Oauth2获取用户的访问令牌,因此在向我的项目验证用户并要求他们管理他们的Youtube数据后,我正在存储访问权限令牌到数据库如何使用Youtube API的访问令牌来获取用户的已打包视频列表
现在我想获取该认证用户上传的视频的详细信息或列表,那么如何使用用户的访问令牌获取其Youtube视频数据?
下面是我的代码
我生成认证URL像
$url = "https://accounts.google.com/o/oauth2/auth";
$params = array(
"response_type" => "code",
"client_id" => "XXXXXXX",
"redirect_uri" => "http://youtube-get.dev/oauth2callback.php",
"scope" => "https://gdata.youtube.com",
"access_type" => "offline"
);
$request_to = $url . '?' . http_build_query($params);
header("Location: " . $request_to);
,并通过调用在oauth2callback.php卷曲我得到的访问令牌
$client_id="XXXXXXX";
$client_secret="XXXXXX";
$redirect_uri="http://youtube-get.dev/oauth2callback.php";
$oauth2token_url = "https://accounts.google.com/o/oauth2/token";
$clienttoken_post = array(
"code" => $code,
"client_id" => $client_id,
"client_secret" => $client_secret,
"redirect_uri" => $redirect_uri,
"grant_type" => "authorization_code"
);
$curl = curl_init($oauth2token_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
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);
if (isset($authObj->refresh_token)){
//refresh token only granted on first authorization for offline access
//save to db for future use (db saving not included in example)
global $refreshToken;
$refreshToken = $authObj->refresh_token;
}
$accessToken = $authObj->access_token;
获得此访问令牌后我如何使用它来获得认证用户的视频列表?
所有的帮助将不胜感激,已经浪费了很多时间。
请告诉我们一些你目前的工作和点是它里面的问题,以及预期的行为和[MCVE]的( http://stackoverflow.com/help/mcve)。 –
好吧,我已经包括了我的代码,无论我现在做了什么 –