问题
I have been trying to use the Soundcloud API to add and remove songs from groups. I am using the soundcloud-python wrapper to enable me to do this easily.
I have got both Auth flows working correctly (either using OAuth2 or using user credentials directly), and I can use the python client to grab information about the logged in user etc. by performing calls as follows:
print client.get('/me').username
This indicates to me that I have correctly passed authorisation, and as I say, I have got this working via both methods.
My problem is when I try to make the following request which is provided as an example to add/remove songs from groups, I will always get a 404 error, whether or not the track already exists in the group (from the example off the Soundcloud API docs, under "Contributing Sounds to a Group"):
# contribute track to group
group = client.put('/groups/%d/contributions/%d' % (group.id, track.id))
If I perform any function on the /groups/{group-id}/contributions/{track-id} via the client object, I will always get a 404 error. If I am not authenticated I will get a 401 error. I have made 100% sure that I have used working group_id/track_id combinations by testing them through the API console, and hard-coding values where necessary to prove the operation.
This is what confuses me - if I use the same form of URI which failed with the python wrapper in the API Console (on the Soundcloud API website), and I am authenticated through OAuth, then the GET/PUT and DELETE all behave as expected on the same group_id's and track_id's which fail through the soundcloud-python wrapper.
Has anyone else had any issues with this? Have they got this working?
Many thanks in advance for any help!
回答1:
The 404 error suggest that you are not authenticated. If that isn't the problem then, http://developers.soundcloud.com/docs/api/guide#uploading says (in "Contributing a Sound to a Group"):
... Similarly, you can also remove contributions. (python example)
import soundcloud
# create a client object with access token
client = soundcloud.Client(access_token='YOUR_ACCESS_TOKEN')
# delete track id 59 from group id 123
client.delete('/groups/123/contributions/59')
回答2:
Update
The pull request I link to below was accepted and merged into the API wrapper.
Just grab the updated source from Github, and this should be fixed.
p.s. Sorry for the late update.
The /contributions
endpoint is buggy - see this github issue.
I've managed to hack the API to make this work until the bug is fixed on SoundCloud's side. Make the following amendments to the client.py file:
def _resolve_resource_name(self, name):
[...]
name = name.rstrip('/').lstrip('/')
if name[-13:] == 'contributions':
return '%s%s/%s' % (self.scheme, self.host, name)
return '%s%s/%s.json' % (self.scheme, self.host, name)
Or see this pull request.
来源:https://stackoverflow.com/questions/11713034/soundcloud-api-adding-removing-songs-from-groups-404-error