RyanCacophony
RyanCacophony

Reputation: 1117

Soundcloud API doesn't explicitly support pagination with json

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?

Upvotes: 5

Views: 1968

Answers (3)

مو سي
مو سي

Reputation: 11

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

Upvotes: 1

marriedjane875
marriedjane875

Reputation: 673

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?

Upvotes: 0

Misha Reyzlin
Misha Reyzlin

Reputation: 13906

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

Upvotes: 14

Related Questions