【问题标题】:SoundCloud API x PythonSoundCloud API x Python
【发布时间】:2015-04-08 04:03:56
【问题描述】:

我是 Python 的真正初学者,但一直在尝试弄乱 SoundCloud API。我遇到的唯一问题(到目前为止)是尝试使用以下方式返回我帐户中的关注用户列表:

打印client.get('/me/followings')

我得到这个作为回报:

<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>

我假设这是因为我没有正确安装资源包装器?

这里是完整的代码:

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

【问题讨论】:

    标签: python soundcloud


    【解决方案1】:

    看起来它对我有用,您有一个 soundcloud.resources 列表,您可以遍历它们并打印出任何相关信息,例如:

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

    【讨论】:

    • 嘿@champion,正如我所说,我对 Python 真的很陌生。你能解释一下你提供的例子吗?在我收到此错误之前,这一切都对我有用:[code]UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 164: ordinal not in range(128)[/code]
    【解决方案2】:

    @Velocity 确保您添加到脚本的顶部,以便我可以正确编码对象

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多