【问题标题】:Soundcloud API doesn't explicitly support pagination with jsonSoundcloud API 不明确支持使用 json 进行分页
【发布时间】:2013-02-21 21:44:29
【问题描述】:

我正在使用的具体示例:

http://api.soundcloud.com/users/dubstep/tracks.json?client_id=YOUR_CLIENT_ID

您将获得他们的前 50 首曲目,但没有像您在 xml version 中看到的那样的 next-href 对象。

但是,您可以使用偏移量和限制,并且它可以按预期工作 - 但是我需要“盲目地”爬过轨道,直到没有更多轨道,这与 XML 版本不同,它为您提供“下一页”结果。我什至不会注意到它是分页的,除非我在搜索 json 对象时偶然发现它正好有 50 条轨道(这甚至是可疑的)。

有计划支持 json 中的 next-href 标签吗?我错过了什么吗?它是缺少的错误吗?

【问题讨论】:

    标签: json api pagination soundcloud


    【解决方案1】:

    您可以使用一个未记录的参数linked_partitioning=1,它将next_href 添加到响应中。

    http://api.soundcloud.com/users/dubstep/tracks.json?client_id=YOUR_CLIENT_ID&linked_partitioning=1

    【讨论】:

      【解决方案2】:

      例如:

      // build our API URL
      $clientid = "Your API Client ID"; // Your API Client ID
      $userid = "/ IDuser"; // ID of the user you are fetching the information for
      
      // Grab the contents of the URL
      //more php get
      $number="1483";
      
      $offset=1300;
      $limit=200;
      
      $soundcloud_url = "http://api.soundcloud.com/users/{$userid}/tracks.json?client_id={$clientid}&offset={$offset}&limit={$limit}";
      $tracks_json = file_get_contents($soundcloud_url);
      $tracks = json_decode($tracks_json);
      
      
      foreach ($tracks as $track) {
          echo "<pre>";
           echo $track->title . ":";
          echo $track->permalink_url . "";
          echo "</pre>";
      }
      

      【讨论】:

        【解决方案3】:

        我已经看到这段代码应该有所帮助(这是在 Ruby 中):

        # start paging through results, 100 at a time
        tracks = client.get('/tracks', :order => 'created_at', :limit => page_size,
                            :linked_partitioning => 1)
        tracks.each { |t| puts t.title }
        

        但是,第一组结果会显示,我什至会在响应末尾看到“next_href”,但是你应该怎么做才能显示下一组结果?

        【讨论】:

        • next_href 中的数据应该是指向下一个 API URL 的链接。我不太使用 ruby​​,所以我不确定如何将这些数据转换成你的 ruby​​“客户端”对象可以处理的东西
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-22
        • 2016-09-29
        • 2020-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多