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)。 –
好吧,我已經包括了我的代碼,無論我現在做了什麼 –