Failed to Get an Upload Token on Radioco
API Guide
With SoundCloud API you tin build applications that take music to the next level. With this guide we explain and provide code examples for a lot of common integration utilise cases like playing and uploading tracks, liking a playlist or discovering new music. If you lot're looking for more than in depth data, feel free to leap to our API Explorer.
At present go ahead and jump to the section you're well-nigh interested in and get started.
- Sign in with SoundCloud
- Authorization Code Menses
- Client Credentials Token Substitution Menstruum
- Refreshing Tokens
- Mobile and Desktop Applications
- Accessing Resources
- Getting Information near Authenticated User
- Uploading Audio Files
- Updating Metadata
- Creating Playlists
- Calculation Tracks to a Playlist
- Accessing Playlists
- Embedding the SoundCloud Widget
- Streaming Tracks
- HTTP Condition Codes
Authentication
Uploading Tracks
Playing Tracks
Follow & Like
Search
Pagination
SoundCloud URLs
Cantankerous Domain Requests
Errors
Authentication
In order to integrate with Soundcloud you need to qualify your application. SoundCloud authentication uses OAuth 2.0, a pop open up standard used by many API providers. OAuth ii.0 allows users to authorize the application without disclosing their username and password.
There are different ways to authenticate with OAuth, depending on the needs of an application you're building.
Supported Authorisation flows:
- Authorization Code: Your application intends to perform actions on a user's behalf (rails upload) besides equally admission user's data (their account, including any private tracks or playlists that they have created or that have been shared with them). In that case your app has to get permission from Soundcloud, and the user, to access SoundCloud on their behalf.
- Client Credentials: Your application intends to access public resources merely. That implies searching for a runway, or a playlist, playback and URL resolution. For these purposes you practice non crave a user session, just an authorized app.
In further sections you can find more detailed information about each of the authentication methods.
| Menses | User Resources Admission | Server-side Implementation |
|---|---|---|
| Authorisation Lawmaking | Yes | Yeah |
| Customer Credentials | No | Yes |
Sign in with SoundCloud
You tin can simplify your registration and sign in process by using a Connect with SoundCloud push. This lets your user know that they can register for your app with ane click using their SoundCloud account. Information technology also grants your app access to their account and gives yous the ability to upload tracks, create playlists and otherwise human action on their behalf.
Authorization Code Menses
To authenticate your server-side spider web awarding you can call our API straight using the API credentials you obtained when you registered your app and redirect the user to the potency URL so that they can log in and approve your request.
- Curl
# authenticate your app through SC Connect # open up in the browser "https://api.soundcloud.com/connect?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&response_type=code" Security Communication
Use the country parameter for CSRF protection. Pass a sufficient random nonce here and verify this nonce again later retrieving the token.
A pop-upwardly window will be opened allowing the user to log in to SoundCloud and approve your app's authorization request. If the user is already signed into SoundCloud, they will exist able to qualify your asking in one click.
Users of your app will exist redirected to the SoundCloud Connect screen.
If the user approves your potency request, they will be sent to the redirect_uri you specified when registering your app. Excerpt the code parameter from the query string and apply information technology to obtain an access token.
- Ringlet
# obtain the admission token $ curl -X POST "https://api.soundcloud.com/oauth2/token" \ -H "accept: application/json; charset=utf-8" \ -H "Content-Type: awarding/x-www-form-urlencoded" \ --data-urlencode "grant_type=authorization_code" \ --information-urlencode "client_id=YOUR_CLIENT_ID" \ --information-urlencode "client_secret=YOUR_CLIENT_SECRET" \ --information-urlencode "redirect_uri=YOUR_REDIRECT_URI" \ --data-urlencode "lawmaking=YOUR_CODE" The returned object has an access_token property and a refresh_token property as well as expires_in and scope. You lot should at present store the object in a database or a data storage of your option. Associate it with the user it belongs to and utilise the access_token from now on instead of sending the user through the authorization menstruation on each API interaction. Utilize the refresh_token to automatically renew the expired token.
- Curl
# brand an authenticated call $ curl "https://api.soundcloud.com/me" \ -H "take: application/json; charset=utf-8" \ -H "Say-so: OAuth ACCESS_TOKEN" Client Credentials Token Exchange Flow
With applications, such equally CLIs, or pure back-finish services you would authenticate the application itself rather than a user. For instance, you lot might want to build an artist's website where you only need an access to their tracks, playlists, or user data. There is no need to get through the connect flow, equally SoundCloud API provides the Client Credentials Flow for these purposes. Yous pass along the client_id and client_secret you have caused at registration to authenticate and get a token.
- Ringlet
# obtain the access token $ scroll -10 POST "https://api.soundcloud.com/oauth2/token" \ -H "accept: application/json; charset=utf-8" \ -H "Content-Type: application/x-world wide web-form-urlencoded" \ --data-urlencode "grant_type=client_credentials" \ --data-urlencode "client_id=YOUR_CLIENT_ID" \ --data-urlencode "client_secret=YOUR_CLIENT_SECRET" Aforementioned way as with the Authorization Lawmaking flow you receive an object that has an access_token, refresh_token properties too as expires_in and scope. Store the object in a database or a data storage of your choice. Associate it with the user information technology belongs to and use the access_token for requesting data from our API. Use the refresh_token to automatically renew the expired token.
Please be aware there is a rate limiting on amount of token yous can asking through the Client Credentials Flow: 50 tokens in 12h per app, and thirty tokens in 1h per IP address. In order to non hit the limit we highly recommend reusing one token betwixt instances of your service and implementing the Refresh Token flow to renew tokens.
Refreshing Tokens
As the access tokens elapse you volition need to periodically refresh them. Currently a token lives around 1 hour. You can set an automatic process that checks the expiration time of a electric current token and updates it using the provided refresh_token. Please note that each refresh token tin only exist used one time.
- Curlicue
# refresh token $ curl -10 POST "https://api.soundcloud.com/oauth2/token" \ -H "have: application/json; charset=utf-viii" \ -H "Content-Type: awarding/ten-www-form-urlencoded" \ --data-urlencode "grant_type=refresh_token" \ --information-urlencode "client_id=YOUR_CLIENT_ID" \ --information-urlencode "client_secret=YOUR_CLIENT_SECRET" \ --data-urlencode "refresh_token=YOUR_TOKEN" \ Mobile and Desktop Applications
You cosign mobile and desktop applications the same style you do for web applications. To make the menstruum smoother, you can utilize a redirect_uri with a custom protocol scheme and set your app as a handler for that protocol scheme. For case, your redirect_uri could exist something like my-app://soundcloud/callback.
When building apps for mobile devices, we recommend using our mobile optimized connect screen by setting display=popup in the authorization URL query string.
Mobile optimized connect screen.
Accessing Resources
All Soundcloud resources (tracks, playlists, users) can only exist accessed by an authenticated applications. That said, every request to our API requires an Authorization header in the post-obit format:
-H "Authorization: OAuth ACCESS_TOKEN"
Note that requests without the header will exist rejected with a 401 Unauthorized error. Bank check the Authentication section to learn nearly supported auth methods.
Getting Data virtually the Authenticated User
Once the user has signed into SoundCloud and approved your app's dominance asking, you volition be able to access their profile and act on their behalf. We accept provided a convenient endpoint for accessing information about the authenticated user.
- Whorl
$ gyre "https://api.soundcloud.com/me" \ -H "accept: application/json; charset=utf-8" \ -H "Authorization: OAuth ACCESS_TOKEN" Uploading Tracks
Tracks are core to SoundCloud. Our API gives you lot the ability to upload, manage and share tracks. Your app can accept an audio file and upload information technology to a user's SoundCloud business relationship. Yous can also manage metadata (including tags) or add the track to playlists. We back up the following formats: AIFF, WAVE, FLAC, OGG, MP2, MP3, AAC, AMR and WMA.
Uploading Sound Files
To upload a rails, ship a Post request with a multipart/form-data media type to the /tracks endpoint.
Request bodies for rail uploads via the API may non be larger than %strong 500MB.
- Curl
$ curlicue -X POST "https://api.soundcloud.com/tracks" \ -H "accept: application/json; charset=utf-eight" \ -H "Authorization: OAuth ACCESS_TOKEN" \ -H "Content-Type: multipart/form-data" \ -F "rails[title]=YOUR_TITLE" \ -F "track[asset_data]=@PATH_TO_A_FILE" If successful, your track will immediately be queued upwardly for encoding.
Updating Metadata
In guild to update a rails's metadata, send a PUT request to the /tracks/:id endpoint, passing in the path of the runway resource and the properties y'all want to update.
You can update the rail artwork using the artwork_data parameter. Please note that at this time information technology is not possible to update the actual track sound file.
For a full listing of properties that can be assail a track resource, come across the endpoint reference.
- Whorl
# Multipart asking $ curlicue -X PUT "https://api.soundcloud.com/tracks/TRACK_ID" \ -H "accept: application/json; charset=utf-8" \ -H "Content-Type: mmultipart/form-information" \ -H "Dominance: OAuth ACCESS_TOKEN" \ -F "track[title]=YOUR_TITLE" \ -F "rails[description]=YOUR_DESCRIPTION" \ -F "track[artwork_data]=PATH_TO_FILE" # Json request $ curl -Ten PUT "https://api.soundcloud.com/tracks/TRACK_ID" \ -H "accept: awarding/json; charset=utf-8" \ -H "Content-Type: awarding/json" \ -H "Authorization: OAuth ACCESS_TOKEN" \ -d '{"rail":{"championship":"NEW TITLE"}}' Creating Playlists
Playlists allow y'all to organize tracks into groups that can be shared together. For case, tracks in an album or in a specific collection can be grouped together using a playlist and so shared to the world. You tin can add together any tracks to a playlist and a track can belong to multiple playlists. Playlists can exist either private or public.
You create playlists through our API by sending the Post request to the /playlists endpoint and providing the data about the playlist, including a list of track ids.
- Whorl
$ curl -X POST "https://api.soundcloud.com/playlists" \ -H "accept: application/json; charset=utf-8" \ -H "Content-Type: application/json" \ -H "Authorization: OAuth ACCESS_TOKEN" \ -d "{'playlist': {'championship':'YOUR_TITLE', 'description':YOUR_DESCRIPTION, 'sharing':'public', 'tracks':[{'id':1},{'id':2},{'id':3}]}}" Adding Tracks to a Playlist
In one case a playlist has been created, yous tin continue to add tracks to it past updating the tracks belongings. You can also update the playlist'southward metadata.
- Gyre
$ curl -X PUT "https://api.soundcloud.com/playlists/PLAYLIST_ID" \ -H "have: awarding/json; charset=utf-8" \ -H "Content-Type: awarding/json" \ -H "Authorization: OAuth ACCESS_TOKEN" \ -d "{'playlist': {'tracks':[{'id':ane}, {'id':2}, {'id':3}]}}" Accessing Playlists
To become a list of tracks in a playlists, send a Become request to the /playlists/:id endpoint with the playlist id.
- Curl
$ curl -10 GET "https://api.soundcloud.com/playlists/PLAYLIST_ID?show_tracks=imitation" \ -H "accept: awarding/json; charset=utf-eight" \ -H "Authorization: OAuth ACCESS_TOKEN" See also:
- /playlists endpoint reference documentation.
Playing Tracks
Yeah, you tin also play tracks and playlists from your application. Depending on your needs, you can embed a player widget, or feed a stream url into your own audio player. You tin also utilise our Widget API to control the player and handle events.
Embedding a SoundCloud Widget
If you have the URL of a track or a playlist, you tin can get the embed code and paste it into your website. Yous can too do this in your application using the oEmbed endpoint. Given a track or playlist URL, you tin can call back all of the information you demand to embed a player.
Example SoundCloud Widget
Streaming Tracks
Annotation if you lot are going to stream from our API you need to attribute properly. Brand sure you've read our Terms and Attribution Guidelines to make sure yous treat our creators content correctly. When using a custom actor you must:
- Credit the uploader equally the creator of the rail
- Credit SoundCloud equally the source by including one of the logos constitute here
- Link to the SoundCloud URL containing the piece of work
- If the track is private link to the contour of the creator
If you don't want to utilise the SoundCloud widget, our API gives y'all the ability to access a runway'south stream URL and utilise your ain player to play tracks from SoundCloud. In lodge to get a URL for streaming, yous tin can request the advisable resource and make annotation of the stream_url property. Send a Become request to that URL and you will get a set of links with available transcodings which you tin choose from.
Notation that as long as the rails is public, y'all can access it with no user associated. If you would like to access the stream URL for a private rail, you'll need to have an authorized user session and a secret_token provided.
- Roll
# 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 $ coil -10 GET "https://api.soundcloud.com/tracks/TRACK_ID/stream" \ -H "accept: application/json; charset=utf-8" \ -H "Authorization: OAuth ACCESS_TOKEN" Restricted Access
Not every track is allowed for streaming off platform. A user might restrict a playback, or a track might be behind a paywall, geo-blocked and then on. In that case a track in response wont have a stream_url available and a field access volition have blocked. If you endeavor to call /tracks/:id/streams endpoint you lot will get an error.
Soundcloud API provides 3 levels of track's access:
-
playable- a track is fully streamable. -
preview- a track'southward preview is available. -
blocked- a runway is non streamable, only metadata is provided.
You can also specify the access when searching or fetching tracks to, for case, avoid showing not-streamable tracks. Our endpoints provide a filter access that accepts an inclusive listing of values.
For detailed information check the API Explorer.
SoundCloud has many social features that make it easier to interact, share and get feedback. The primary manner that SoundCloud users interact is past leaving comments on each other's tracks.
Our API allows you to leave comments on tracks by calling the Post method with the /tracks/:track_id/comments path and data about the comment. Include the timestamp to make it a timed comment.
Notation that you cannot exit comments on tracks if the creator has disabled comments.
- Curl
$ curl -X Post "https://api.soundcloud.com/tracks/YOUR_TRACK_ID/comments" \ -H "accept: awarding/json; charset=utf-viii" \ -H "Content-Type: awarding/json; charset=utf-8" \ -H "Authorization: OAuth ACCESS_TOKEN" \ -d "{'comment':{'body':'YOUR_COMMENT'}}" Note that the timestamp value is in milliseconds and represents the amount of fourth dimension from the offset of the track. If yous omit the timestamp, the annotate volition exist a non-timed one.
You tin also get a listing of comments for a specified track.
- Curl
$ curl -10 GET "https://api.soundcloud.com/tracks/YOUR_TRACK_ID/comments?limit=3&linked_partitioning=true" \ -H "accept: application/json; charset=utf-eight" \ -H "Authorization: OAuth ACCESS_TOKEN" See also:
- /tracks endpoint reference documentation.
Follow & Like
Your application can take reward of SoundCloud's social features past allowing users to follow other users and similar tracks or playlists. Post-obit and liking allows SoundCloud users to customize their experience. Tracks created and reposted by people your user follows will be available in their activity feed.
You can follow a user using the /me/followings/:user_id endpoint.
- Curl
$ whorl -X PUT "https://api.soundcloud.com/me/followings/USER_ID" \ -H "accept: application/json; charset=utf-eight" \ -H "Authorization: OAuth ACCESS_TOKEN" Liking a rails or playlist is done using the /likes/ endpoints.
- Roll
# liking a track $ curl -Ten POST "https://api.soundcloud.com/likes/tracks/TRACK_ID" \ -H "accept: application/json; charset=utf-8" \ -H "Potency: OAuth ACCESS_TOKEN" # liking a playlist $ curl -10 POST "https://api.soundcloud.com/likes/playlists/PLAYLIST_ID" \ -H "accept: awarding/json; charset=utf-8" \ -H "Authorization: OAuth ACCESS_TOKEN" Search
Resource such as tracks, users, playlists can exist searched using our API. Most endpoints will accept a q param which you lot can use to specify a keyword to search for in fields like title, username, description, etc. depending on the resource type.
- Whorl
# search pnly for playable tracks $ curl -X GET "https://api.soundcloud.com/tracks?q=howdy&ids=1,two,3&genres=Pop,House&admission=playable&limit=iii&linked_partitioning=truthful" \ -H "have: application/json; charset=utf-8" \ -H "Dominance: OAuth ACCESS_TOKEN" You tin can also specify ranges for bpm, elapsing, and more.
- Ringlet
# search pnly for playable tracks $ curlicue -10 GET "https://api.soundcloud.com/tracks?q=hello&ids=1,2,3&genres=Pop,Business firm&bpm%5Bfrom%5D=120&elapsing%5Bfrom%5D=30000&access=playable&limit=3&linked_partitioning=true" \ -H "accept: application/json; charset=utf-8" \ -H "Say-so: OAuth ACCESS_TOKEN" For a complete list of search fields and filters, please cheque the /search section for the resource type y'all'd similar to search.
Pagination
Nearly results from our API are returned as a drove. The number of items in the collection returned is express to 50 by default with a maximum value of 200. Most endpoints support a linked_partitioning parameter that allows yous to folio through collections. When this parameter is passed, the response will contain a next_href holding if there are additional results. To fetch the next page of results, only follow that URI. If the response does not incorporate a next_href property, you lot have reached the stop of the results.
- Whorl
# fetch beginning 25 user'southward playlists $ ringlet -X Get "https://api.soundcloud.com/me/playlists?show_tracks=false&linked_partitioning=truthful&limit=25" \ -H "accept: awarding/json; charset=utf-8" \ -H "Authorisation: OAuth ACCESS_TOKEN" # response contains 'next_href': "https://api.soundcloud.com/playlists?show_tracks=false&page_size=25&cursor=1234567" SoundCloud URLs
If you lot accept a permalink URL to a particular resource, merely demand more data such as an ID or other property, you tin can utilize the /resolve endpoint to extract a full representation of the resources.
- Curl
$ curl -X Get "https://api.soundcloud.com/resolve?url=https://soundcloud.com/PERMALINK" \ -H "take: */*" \ -H "Authorization: OAuth ACCESS_TOKEN" Come across also:
- /resolve endpoint reference documentation.
Cantankerous Domain Requests
Our API supports CORS for making cantankerous domain requests. This means you can access SoundCloud API endpoints from JavaScript running in the browser. By requesting results formatted as JSON, y'all will be able to parse and utilise the response immediately.
<script src="http://code.jquery.com/jquery-one.7.2.js"></script> <script> var url = 'https://api.soundcloud.com/tracks'; $.getJSON(url, function(tracks) { $(tracks).each(function(track) { console.log(rails.championship); } }); </script> We too support JSONP, which can be used past passing a callback parameter in the query string of the URL y'all are requesting.
Errors
When an error occurs, our API will return an appropriate HTTP status lawmaking and an mistake message description.
In this department:
- HTTP Condition Codes
- Curl
# endeavor fetching a non-existing user $ gyre -10 GET "https://api.soundcloud.com/users/INVALID_ID" \ -H "accept: application/json; charset=utf-8" \ -H "Authorization: OAuth ACCESS_TOKEN" # response 404 Error: Not Constitute { "lawmaking": 404, "message": "404 - Not Found", "link": "https://developers.soundcloud.com/docs/api/explorer/open-api", "status": "404 - Not Institute", "errors": [ { "error_message": "404 - Non Found" } ], "error": nil } HTTP Status Codes
The response from SoundCloud will have an HTTP status code that will assist y'all decide the cause of the error. Our API tries to apply the advisable HTTP status code to point the type of trouble encountered.
Below is an overview of what those codes hateful, along with some suggestions that might help y'all prepare things.
400 Bad Asking
This is likely to be caused by a programming mistake on your part. Check the requirements of the endpoint you lot're calling in the API Explorer.
401 Unauthorized
This means that nosotros were not able to authenticate you based on the information provided in the request. Make sure you're sending an Authorization header.
Our public endpoints volition piece of work with an access token acquired through the Client Credentials menses. Acting on behalf of another user is different. The Hallmark department gives a detailed explanation of how this works.
If you're connecting using OAuth, don't forget that tokens can expire. These will demand to be refreshed. Not doing and so can also result in getting a 401 fault.
If you need to check your application's details, use the Your Applications page. This will include the client_id for your awarding.
403 Forbidden
Y'all don't have access to whatever it is y'all're asking for.
404 Non Found
You're asking for something that doesn't be. Check the URL that you're requesting.
406 Not Accessible
This ways it wasn't possible to respond with the format you requested. Check the Have header that you lot're sending.
422 Unprocessable Entity
The asking was valid, but one or more of the parameters looks a little screwy. Information technology'due south possible that you sent data in the wrong format. One instance would be providing an array when we expected a string.
429 Too Many Requests
To keep the amount of spam on SoundCloud equally low every bit possible, our API limits the rate at which you can perform certain actions. Read the Rate Limits page to find out more.
500 Internal Server Error
Uh-oh. Something went wrong on our side. We're deplorable. We continue rails of these, and nosotros'll try to set it!
503 Service Unavailable
This means that nosotros're having some trouble, and our servers are too decorated to handle your request. You'll want to check for these and give your user a chance to retry the request. We keep runway of these and try to make sure they don't happen.
504 Gateway Timeout
This means the asking is taking too long. All the same, it doesn't ever mean that we didn't receive your request. We could even so be chugging abroad on the changes you made, and this means that yous may want to check before retrying.
Source: https://developers.soundcloud.com/docs
Post a Comment for "Failed to Get an Upload Token on Radioco"