Velocity
Velocity

Reputation: 125

SoundCloud API x Python

I am a real beginner with Python but have been trying to mess around with the SoundCloud API. The only issue I'm having (thus far) is trying to return a list of followed users on my account using:

print client.get('/me/followings')

I get this in return:

<soundcloud.resource.Resource object at 0x02C51130>, <soundcloud.resource.Resource object at 0x02C51150>, <soundcloud.resource.Resource object at 0x02C51170>, <soundcloud.resource.Resource object at 0x02C51190>, <soundcloud.resource.Resource object at 0x02C511B0>, <soundcloud.resource.Resource object at 0x02C511D0>, <soundcloud.resource.Resource object at 0x02C511F0>, <soundcloud.resource.Resource object at 0x02C51210>, <soundcloud.resource.Resource object at 0x02C51230>, <soundcloud.resource.Resource object at 0x02C51250>

I am assuming this is because I do not have the resource wrapper correctly installed?

Here is the full code:

import soundcloud
import simplejson as json

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

# print authenticated user's username
print client.get('/me').username

tracks = client.get('/me/followings')

print tracks

Upvotes: 0

Views: 809

Answers (2)

21st
21st

Reputation: 2111

@Velocity make sure you add to the top of your script, so I can encode the objects properly

# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')

Upvotes: 0

AChampion
AChampion

Reputation: 30258

Looks like it is working to me, you have a list of soundcloud.resources you can loop over them and print out any relevant information, e.g.:

for track in tracks:
     for k, v in track.fields().items():
          print "{}: {}".format(k, v)

Upvotes: 1

Related Questions