audiooauthaudio-streamingsoundcloudhttp-status-code-401

The Soundcloud Stream URL returns an error code 401


This URL used to function well in my browser, but now it returns an error code of 401.

URL: https://api.soundcloud.com/tracks/881102623/stream?client_id=fbb40e82698631328efb400b0700834f

Browser Response:

{
  "code": 401,
  "message": "A request must contain the Authorization header. For details please refer to https://developers.soundcloud.com/blog/security-updates-api.",
  "link": "https://developers.soundcloud.com/docs/api/explorer/open-api",
  "status": "401     - Unauthorized",
  "errors": [
    {
      "error_message": "A request must contain the Authorization header. For details please refer to https://developers.soundcloud.com/blog/security-updates-api."
    }
  ],
  "error": null
}

Please assist us in resolving this. Thank you in advance.


Solution

  • The method stream requires an authorization header.

    # request a track you want to stream
    $ curl -X GET "https://api.soundcloud.com/tracks/TRACK_ID" \
           -H  "accept: application/json; charset=utf-8" \
           -H "Authorization: OAuth ACCESS_TOKEN"
    
    # extract stream_url when available from a response
    $ curl -X GET "https://api.soundcloud.com/tracks/TRACK_ID/stream" \
             -H  "accept: application/json; charset=utf-8" \
             -H "Authorization: OAuth ACCESS_TOKEN"
    

    You are getting 401 - Unauthorized because you have not supplied an access token, with permissions to access track 881102623.

    You should consult the authentication guide on how to request an access token.