2013-03-06 52 views
4

具體例子分頁我正在同:的SoundCloud API不明確支持JSON的

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

你會得到他們的第50條軌道,但沒有下HREF的物體,像你看到了什麼在xml version

但是,您可以使用偏移量和限制,它的工作方式與預期的一樣 - 但之後我需要「盲目」爬過曲目,直到沒有更多曲目,這與使用「下一頁」的結果。當我搜索json對象時,我甚至都沒有注意到它被分頁,除非偶然,並且注意到正好有50條曲目(甚至是可疑的)。

是否有計劃支持json中的下一個href標記?我錯過了什麼嗎?它缺少一個缺陷嗎?

回答

0

sI've是應該幫助(這是紅寶石):

# 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「,但是你應該怎麼做才能使下一組結果顯示出來?

+0

從'next_href'的數據應該是下一個API URL的鏈接。我不會用ruby工作太多,所以我不知道如何將這些數據轉換成你的ruby「客戶」對象可以處理的東西 – RyanCacophony 2016-01-06 22:17:03

0

爲前:

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