使用 created_at 过滤器查询 Soundcloud API [英] Query Soundcloud API using created_at filter

查看:35
本文介绍了使用 created_at 过滤器查询 Soundcloud API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Python 中将 created_at 过滤器用作查询的一部分?我将它添加到我的查询过滤器中,尝试了几种不同的方法,但它似乎忽略了那个特定的过滤器.返回的结果包含从上周到 3 年前的所有内容,我只是在寻找最近的曲目.我必须相信这是可行的......

Is it possible to use the created_at filter as part of a query in Python? I added it into my query filters, trying several different ways, but it seems to ignore that particular filter. The results that come back contain everything from last week to 3 years ago, and I'm only looking for recent tracks. I have to believe this is doable somehow...

stamp = "2013/07/01 09:24:50 +0000"

tracks = client.get('/tracks', q='Metallica', genre='', duration={
'from': 1800000
}, created_at={
'from': stamp
}, limit='5', tags='Metal')

我也尝试过直接输入日期时间戳而不是作为变量输入,结果相同.我只是在这里的某个地方搞砸了代码吗?或者你真的不能为你的查询结果指定 created_at 日期吗?

I've also tried just entering the datetime stamp directly instead of as a variable, with the same results. Am I just botching the code somewhere here? Or can you really not specify the created_at date for your query results?

推荐答案

是的!可以在 Python 中将 created_at 过滤器用作查询的一部分.

Yes! It is possible to use the created_at filter as part of a query in Python.

我不知道 SoundCloud API 如何确定每个过滤器的优先级,因此添加更多过滤器可能会导致意外结果.

I do not know how the SoundCloud API prioritizes each of the filters, so it is possible that adding more filters may lead to unexpected results.

仅将过滤器限制为过滤器 {query, created_at} 会产生您想要的结果.

Limiting the filters simply to the filters {query, created_at} yield your desired result.

# https://github.com/soundcloud/soundcloud-python
import soundcloud 

# Authentication
CLIENT_ID = 'insert_client_id_here'
client = soundcloud.Client(client_id=CLIENT_ID) 

# Call GET request with parameters
# excludes: {genres,tags,duration}
# includes: {order,limit} for organization
stamp = "2013/07/01 09:24:50 +0000"
tracks = client.get('/tracks',
                q='Metallica',
                created_at= {'from': stamp},
                order='created_at', 
                limit=5, 
                )

# Print the results
for i, v in enumerate(tracks):
    print i, v.title, v.created_at

这篇关于使用 created_at 过滤器查询 Soundcloud API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆