【问题标题】:How can I use Youtube API's access token to get the list of user's uploded video如何使用 Youtube API 访问令牌获取上传视频的用户列表
【发布时间】:2015-09-28 11:53:18
【问题描述】:

我已经通过 Oauth2 获得了用户的访问令牌,所以在对我的项目验证用户并要求他们管理他们的 Youtube 数据后,我将访问令牌存储到数据库中

现在我想获取该经过身份验证的用户上传的视频的详细信息或列表,那么如何使用用户的访问令牌来获取他们的 Youtube 视频数据?

下面是我的代码

我生成身份验证网址,如

$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 中调用 curl,我得到了访问令牌

$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
  • 好的,我已经包含了我的代码,无论我到目前为止做了什么

标签: php api video youtube


【解决方案1】:

验证后使用下面的 url 来获取验证用户的视频

https://www.googleapis.com/youtube/v3/search?part=snippet&forMine=true&maxResults=25&q={your searchparameter}&type=video&key={your App Key}

【讨论】:

    猜你喜欢
    • 2012-12-20
    • 2012-11-25
    • 2015-06-08
    • 2015-12-02
    • 2015-10-30
    • 2019-11-22
    • 2014-05-02
    • 2013-09-22
    相关资源
    最近更新 更多