简体   繁体   中英

SoundCloud-Python AttributeError: 'ResourceList' object has no attribute 'collection'

I am following the guidelines here https://github.com/soundcloud/soundcloud-python (built around Python requests), and I am trying to list all the tracks in my soundcloud account ( https://developers.soundcloud.com/docs/api/reference#tracks ), with their correspoding metrics such as plays, likes, etc.

# create client object with app and user credentials
client = soundcloud.Client(client_id=client_id,
                           client_secret=client_secret,
                           username=username,
                           password=password)

# print authenticated user's username
name        =  client.get('/me').username
track_count =  client.get('/me').track_count
tracks      =  client.get('/tracks')
print name, track_count

I can get the values in the print statement, but if I try to do this (taken from the example)

for track in tracks.collection:
    print track.title

I get this error:

AttributeError: 'ResourceList' object has no attribute 'collection'

Any idea how to fix this? Thanks

Try:

for track in tracks:
    print track.title

You could also try to define tracks as follows:

tracks      =  client.get('/tracks.json')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM