如何获得优酷access

如何获得优酷access

本文介绍了如何获得优酷access_token的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到优酷账号的access_tokenrefresh_token?

Where can I find the access_token, refresh_token in my youku account?

我找到了如何使用外部脚本通过 API 将视频上传到优酷网,但我需要 access_tokenrefresh_token 才能使用它.>

I found out how to upload video to youku.com using external script with the use of a API, but I need access_token, refresh_token to use it.

推荐答案

您需要对优酷应用进行授权,并使用get代码获取token.

You need to authorize your Youku app and to use the get code to obtain a token.

  1. 转到https://openapi.youku.com/v2/oauth2/authorize?client_id={YOURCLIENTID}&response_type=code&redirect_uri={YOURCALLBACKURL}.
  2. 接受授权.您将被重定向到您的回调 URL.请注意,它应该与您在创建优酷应用程序时输入的相同(同样的协议).
  3. 通过对 执行 POST CURL 调用,使用 get 参数代码获取您的访问令牌https://openapi.youku.com/v2/oauth2/token 带有以下参数

if(isset($_GET['code']))
{
    $url    = "https://openapi.youku.com/v2/oauth2/token";
    $params = array(
        "client_id"     => $client_id,
        "client_secret" => $client_secret,
        "grant_type"    => 'authorization_code',
        "code"      => $_GET['code'],
        "redirect_uri"  => $callback_url
    );

    $str_params = http_build_query($params);
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $str_params);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($ch);

    echo $result;
}

$result 将是一个包含 access_token 的 json 数组 {"access_token":"3cc08bffcd48a86a0e540f9ed1be42f4","expires_in":"2592000","re​​fresh_token":"f8d79ce2009"f8d79ce2009"f8d78ce2009"6cbfcd48a86a0e540f9ed1be42f4"

The $result will be a json array containing the access_token {"access_token":"3cc08bffcd48a86a0e540f9ed1be42f4","expires_in":"2592000","refresh_token":"f8d78ce2005c9d1e0b62cd29f61ba3f9","token_type":"bearer"}

更多信息在这里:http://open.youku.com/docs/docs?id=101

这篇关于如何获得优酷access_token的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 14:23