使用created_at筛选查询的SoundCloud API [英] Query Soundcloud API using created_at filter
问题描述
是否有可能使用created_at过滤器在Python查询的一部分?我添加到我的查询过滤器,尝试几种不同的方式,但它似乎忽略特定的过滤器。回来的结果中包含了从上周到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')
我也试过刚刚进入日期时间戳,而不是直接作为变量,具有相同的结果。我只是搞坏了code这里的某个地方?或者,你能真的不适合你的查询结果指定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?
推荐答案
是的!有可能使用created_at滤波器作为在Python查询的一部分。
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.
限制过滤器只是过滤器{查询,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屋!