Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
链接分区的Soundcloud API python问题_Python_Pagination_Soundcloud - Fatal编程技术网

链接分区的Soundcloud API python问题

链接分区的Soundcloud API python问题,python,pagination,soundcloud,Python,Pagination,Soundcloud,关于Soundcloud API指南() 读取100条以上数据的示例如下: # get first 100 tracks tracks = client.get('/tracks', order='created_at', limit=page_size) for track in tracks: print track.title # start paging through results, 100 at a time tracks = client.get('/tracks',

关于Soundcloud API指南() 读取100条以上数据的示例如下:

# get first 100 tracks
tracks = client.get('/tracks', order='created_at', limit=page_size)
for track in tracks:
    print track.title

# start paging through results, 100 at a time
tracks = client.get('/tracks', order='created_at', limit=page_size,
                    linked_partitioning=1)
for track in tracks:
    print track.title
我很确定这是错误的,因为我发现“tracks.collection”需要引用,而不仅仅是“tracks”。基于GitHub python soundcloud API wiki,它应该更像这样:

tracks = client.get('/tracks', order='created_at',limit=10,linked_partitioning=1)
while tracks.collection != None:
 for track in tracks.collection:
  print(track.playback_count)
 tracks = tracks.GetNextPartition()
我删除了最后一行的缩进(我认为wiki上有一个错误,它在for循环中,这对我来说没有意义)。这适用于第一个循环。但是,这不适用于连续页面,因为找不到“GetNextPartition()”函数。我尝试了最后一行,如下所示:

  tracks = tracks.collection.GetNextPartition()
……但没有成功

也许我把版本弄混了?但在从这里下载版本后,我尝试使用Python 3.4运行此功能:


非常感谢任何帮助

我在SoundCloud开发者论坛上找到了这个解决方案,对任何关心这个问题的人来说都是如此。它从最初的案例(搜索曲目)稍微修改为列出我自己的追随者。诀窍是反复调用client.get函数,将先前返回的“users.next_href”作为指向下一页结果的请求传递。万岁

pgsize=200
c=1
me = client.get('/me')
#first call to get a page of followers
users = client.get('/users/%d/followers' % me.id, limit=pgsize, order='id',
                   linked_partitioning=1)
for user in users.collection:
    print(c,user.username)
    c=c+1
#linked_partitioning means .next_href exists
while users.next_href != None:
 #pass the contents of users.next_href that contains 'cursor=' to
 #locate next page of results
 users = client.get(users.next_href, limit=pgsize, order='id',
                    linked_partitioning=1)
 for user in users.collection:
     print(c,user.username)
     c=c+1