How to get youku access_token

后端 未结 2 1133
忘掉有多难
忘掉有多难 2021-01-28 05:12

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

I found out how to upload video to youku.com using external script with t

2条回答
  •  暖寄归人
    2021-01-28 05:56

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

    1. Go to https://openapi.youku.com/v2/oauth2/authorize?client_id={YOURCLIENTID}&response_type=code&redirect_uri={YOURCALLBACKURL}.
    2. Accept the authorization. You will be redirected to your callback URL. Be careful, it should be the same than the one you entered while creating your Youku application (same protocol too).
    3. Use the get parameter code to get your access token by doing a POST CURL call to https://openapi.youku.com/v2/oauth2/token with the following parameters

      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;
      }
      

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

    More infor here : http://open.youku.com/docs/docs?id=101

提交回复
热议问题