Skip to content

Latest commit

 

History

History
 
 

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>KKBOX OpenAPI SDK for Python &mdash; KKBOX Open/Partner API  documentation</title>
  

  
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F_static%2Fcss%2Ftheme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fgenindex.html"/>
        <link rel="search" title="Search" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fsearch.html"/>
    <link rel="top" title="KKBOX Open/Partner API  documentation" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Findex.html"/>
        <link rel="prev" title="KKBOX Open API Developer SDK" href="proxy.php?url=https%3A%2F%2Fgithub.com%2Findex.html"/> 

  
  <script src="proxy.php?url=https%3A%2F%2Fgithub.com%2F_static%2Fjs%2Fmodernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Findex.html" class="icon icon-home"> KKBOX Open/Partner API
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="proxy.php?url=https%3A%2F%2Fgithub.com%2Fsearch.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23">KKBOX OpenAPI SDK for Python</a><ul>
<li class="toctree-l2"><a class="reference internal" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23installation">Installation</a></li>
<li class="toctree-l2"><a class="reference internal" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23test">Test</a></li>
<li class="toctree-l2"><a class="reference internal" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23how-to-use-the-sdk">How to use the SDK</a></li>
<li class="toctree-l2"><a class="reference internal" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23generate-the-sdk-documentation">Generate the SDK documentation</a><ul>
<li class="toctree-l3"><a class="reference internal" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23api-documentation">API Documentation</a></li>
<li class="toctree-l3"><a class="reference internal" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23license">License</a></li>
</ul>
</li>
</ul>
</li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Findex.html">KKBOX Open/Partner API</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Findex.html">Docs</a> &raquo;</li>
        
      <li>KKBOX OpenAPI SDK for Python</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F_sources%2FREADME.md.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="kkbox-openapi-sdk-for-python">
<span id="kkbox-openapi-sdk-for-python"></span><h1>KKBOX OpenAPI SDK for Python<a class="headerlink" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23kkbox-openapi-sdk-for-python" title="Permalink to this headline">¶</a></h1>
<p>The SDK is for accessing various metadata of KKBOX tracks, albums, artist, playlists and stations.</p>
<div class="section" id="installation">
<span id="installation"></span><h2>Installation<a class="headerlink" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23installation" title="Permalink to this headline">¶</a></h2>
<p>Source installation</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">[</span><span class="n">sudo</span><span class="p">]</span> <span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">install</span>
</pre></div>
</div>
<p>Pypi installation</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pip</span> <span class="n">install</span> <span class="n">kkbox</span><span class="o">-</span><span class="n">developer</span><span class="o">-</span><span class="n">sdk</span>
</pre></div>
</div>
<p>The package works with Python 2 and Python 3.</p>
</div>
<div class="section" id="test">
<span id="test"></span><h2>Test<a class="headerlink" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23test" title="Permalink to this headline">¶</a></h2>
<p>First, go to https://developer.kkbox.com/ to get client id and client secret. If the site is unavailable, you can also contact vincentchiang or chrisyuan at KKBOX to get client id and client secret.</p>
<p>Second, create <code class="docutils literal"><span class="pre">client.py</span></code> in the <code class="docutils literal"><span class="pre">test</span></code> directory and create a class named ClientInfo, and put your client id and client secret in it. The content will be like:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">ClientInfo</span><span class="p">():</span>
    <span class="n">client_id</span> <span class="o">=</span> <span class="s2">&quot;YOUR_CLIENT_ID&quot;</span>
    <span class="n">client_secret</span> <span class="o">=</span> <span class="s2">&quot;YOUR_CLIENT_SECRET&quot;</span>
</pre></div>
</div>
<p>And then we can run the tests.</p>
</div>
<div class="section" id="how-to-use-the-sdk">
<span id="how-to-use-the-sdk"></span><h2>How to use the SDK<a class="headerlink" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23how-to-use-the-sdk" title="Permalink to this headline">¶</a></h2>
<p>First we have to obtain the access token.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">kkbox_developer_sdk.auth_flow</span> <span class="k">import</span> <span class="n">KKBOXOAuth</span>
<span class="n">auth</span> <span class="o">=</span> <span class="n">KKBOXOAuth</span><span class="p">(</span><span class="n">CLIENT_ID</span><span class="p">,</span> <span class="n">CLIENT_SECRET</span><span class="p">)</span>
<span class="n">token</span> <span class="o">=</span> <span class="n">auth</span><span class="o">.</span><span class="n">fetch_access_token_by_client_credentials</span><span class="p">()</span>
</pre></div>
</div>
<p>After obtaining the access token, you may call APIs like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">kkbox_partner_sdk.api</span> <span class="k">import</span> <span class="n">KKBOXAPI</span>
<span class="n">kkboxapi</span> <span class="o">=</span> <span class="n">KKBOXAPI</span><span class="p">(</span><span class="n">token</span><span class="p">)</span>
<span class="n">artist_id</span> <span class="o">=</span> <span class="s1">&#39;8q3_xzjl89Yakn_7GB&#39;</span>
<span class="n">artist</span> <span class="o">=</span> <span class="n">kkboxapi</span><span class="o">.</span><span class="n">artist_fetcher</span><span class="o">.</span><span class="n">fetch_artist</span><span class="p">(</span><span class="n">artist_id</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="generate-the-sdk-documentation">
<span id="generate-the-sdk-documentation"></span><h2>Generate the SDK documentation<a class="headerlink" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23generate-the-sdk-documentation" title="Permalink to this headline">¶</a></h2>
<p>The SDK documentation depends on Sphinx and recommonmark, so first you have to install them.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pip</span> <span class="n">install</span> <span class="n">Sphinx</span> <span class="n">recommonmark</span>
</pre></div>
</div>
<p>Then generate documentation by sphinx:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">sphinx</span><span class="o">-</span><span class="n">apidoc</span> <span class="o">-</span><span class="n">o</span> <span class="n">doc</span> <span class="o">-</span><span class="n">f</span> <span class="n">kkbox_developer_sdk</span>
<span class="n">cd</span> <span class="n">doc</span>
<span class="n">make</span> <span class="n">html</span>
</pre></div>
</div>
<div class="section" id="api-documentation">
<span id="api-documentation"></span><h3><a class="reference external" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3Ca+href%3D"https://kkbox.gelato.io/">API" rel="nofollow">https://kkbox.gelato.io/">API Documentation</a><a class="headerlink" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23api-documentation" title="Permalink to this headline">¶</a></h3>
</div>
<div class="section" id="license">
<span id="license"></span><h3>License<a class="headerlink" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%23license" title="Permalink to this headline">¶</a></h3>
<p>Copyright 2017 KKBOX Technologies Limited</p>
<p>Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>   <span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">www</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">org</span><span class="o">/</span><span class="n">licenses</span><span class="o">/</span><span class="n">LICENSE</span><span class="o">-</span><span class="mf">2.0</span>
</pre></div>
</div>
<p>Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.</p>
</div>
</div>
</div>


           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
      
        <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Findex.html" class="btn btn-neutral" title="KKBOX Open API Developer SDK" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, Sharon Yang.

    </p>
  </div>
  Built with <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3Ca+href%3D"http://sphinx-doc.org/">Sphinx</a" rel="nofollow">http://sphinx-doc.org/">Sphinx</a> using a <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3Ca+href%3D"https://github.com/snide/sphinx_rtd_theme">theme</a">https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3Ca+href%3D"https://readthedocs.org">Read" rel="nofollow">https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'./',
            VERSION:'',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="proxy.php?url=https%3A%2F%2Fgithub.com%2F_static%2Fjquery.js"></script>
      <script type="text/javascript" src="proxy.php?url=https%3A%2F%2Fgithub.com%2F_static%2Funderscore.js"></script>
      <script type="text/javascript" src="proxy.php?url=https%3A%2F%2Fgithub.com%2F_static%2Fdoctools.js"></script>

  

  
  
    <script type="text/javascript" src="proxy.php?url=https%3A%2F%2Fgithub.com%2F_static%2Fjs%2Ftheme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>