Soundcloud API doesn't explicitly support pagination with json

这一生的挚爱 提交于 2019-12-07 04:30:46

问题


Specific example I was working with:

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

You'll get their first 50 tracks, but there is not next-href object like what you see in the xml version.

However, you can use offset and limit and it works as expected- but then I would need to "blindly" crawl through tracks until there are no more tracks, unlike with the XML version which gives you the "next page" of results. I wouldn't have even noticed it was paginated except by chance when I was searching the json object and noticed there was exactly 50 tracks (which is suspiciously even).

Is there a plan to support the next-href tag in json? Am I missing something? is it a bug that it's missing?


回答1:


There is an undocumented parameter you can use linked_partitioning=1, that will add next_href to the response.

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




回答2:


for ex :

// 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:


sI've seen this code is supposed to help (this is in 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 }

However, the first set of results will show and i'll even see the "next_href" at the end of the response, but what are you supposed to do, to make the next set of results show?



来源:https://stackoverflow.com/questions/15258561/soundcloud-api-doesnt-explicitly-support-pagination-with-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!