ioscocoasoundcloud

SoundCloud cocoa wrapper can't access resource without account


Trying to access a public endpoint in the SoundCloud API (https://api.soundcloud.com/tracks.json), sending nil for account to the SoundCloudAPI Library.

API response:

error: Error Domain=NXOAuth2HTTPErrorDomain Code=401 "HTTP Error: 401" UserInfo=0x7556ff0 {NSLocalizedDescription=HTTP Error: 401}

I quote their GitHub repository's general usage guide (https://github.com/soundcloud/CocoaSoundCloudAPI/blob/master/GeneralUsage.md):

You can call this method without an account (nil) for anonymous requests or with the account you get from [SCSoundCloud account].

Which as I can see in http://developers.soundcloud.com is a resource I am allowed to use without OAuth.

Any thoughts ?


Solution

  • You must append ?consumer_key=APP_KEY to the URL of the request, thus example: https://api.soundcloud.com/tracks.json?consumer_key=APP_KEY

    I found confirmation of this in their somewhat abandoned Google groups page here: https://groups.google.com/forum/?fromgroups#!topic/soundcloudapi/ptBbe_TWSj8

    It seemed an odd omission from the general usage page on github and also omitted unless otherwise mistaken from their developer website.

    EDIT

    I did come across another piece of information about this, the developer site does mention a client_id GET parameter, this differs from the consumer_key however, it would be great if we could get confirmation on whether to use consumer_key or client_id for unauthorised, public API calls.

    It also seems a little odd that the SoundCloud API library doesn't append this (which ever one appropriate) to the URL upon receiving a nil account argument. It seems logical to automatically switch to a correct api call if a user account object is missing.