RSoundCloud
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Introduction
The RSoundCloud package contains two functions with which to query the SoundCloud API. It further contains one convenience function aimed at helping the user to obtain a client id. This id is necessary to query the API.
Package information
- package name: RSoundCloud
- GitHub link: https://github.com/JasperHG90/RSoundCloud
- issue reports: https://github.com/JasperHG90/RSoundCloud/issues
Installing
The package is available from GitHub. We can install it via the ‘devtools’ package.
Setting up RSoundCloud
In order to query the API, you need to register as a soundcloud developer. You can simply do this with your existing soundcloud account. Then, you need to register an application and copy the ‘client id’ to R. You can do this by calling the loginDetails
function.
This function simply returns a list with your client ID. At this point, you’re all set.
Querying the SoundCloud API
RSoundCloud contains two functions to query the SoundCloud API: SCapi_general
and SCapi_specific
.
Making generic queries
SCapi_general
can be used for generic queries (e.g. users, comments, tracks). This is similar to the Twitter firehose.
By default, the SCapi_general
function returns 50 results. Additionally, the SoundCloud API returns at most 200 results per query. Querying more than 200 results is possible by paginating through the results.
You can also specify an offset. The offset value determines at what point the query starts. That is, with an offset value of 1000 we start querying from user 1000.
The filter
argument can be used to filter the results.
Note that this argument only takes a list as an value. For an overview of the various filters, you can consult the SoundCloud API documentation
Searches are similar for tracks and comments.
Filters can also be used for tracks and comments.
Althrough you can use multiple filters, a lot of combinations return errors. Consult the SoundCloud API documentation for more information.
This returns the following error:
When querying groups, it is not uncommon to get a ‘502 Bad Gateway’ - error. As such, queries for groups should be limited to 25.
Currently, it is not possible to increase the limit and paginate per 25 results. If you really want to paginate through more than 25 results for groups, you can change offset
to paginate through the results.
Making specific queries
SCapi_specific
can be used to query information about specific users, tracks, groups etc. It allows you to search by soundcloud name, soundcloud id, or by url.
Note that the URL does not necessarily have to point to the main page of a user.
This works because we specify the query_type
argument to look for users (and not likes). Selecting “users” will always return the generic information about a user.
If we want to query the tracks belonging to a user, we have several options.
Both of these options work. In method 1, the URL we provide is merely used to resolve the user name (see SoundCloud documentation on resolving). This is governed by the query_type
argument, which is specified to look for “users”. The get
argument then stipulates that we are looking for the tracks belonging to that user (see the SoundCloud documentation on GET).
For method 2, we provide a direct URL to the tracks of the user, and tell SCapi_specific
to query tracks directly via the query_type
argument.
As with the SCapi_general
function, we can add filters to narrow down our search.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.