How to display playback_count for a user using the SoundCloud API


I am trying to display the total track views ("playback_count") for a specific SoundCloud user using the SoundCloud API.

According to the API documentation I get the info using the below function call:


This is fine because it displays the number "13158665".

What is this number? Is it the trackid?

I need to get the "playback_count" for a user using the users username.

I tried getting the UserId from the Username using this:

$soundcloud_playsAPI = "MY_SOUNDCLOUD_API_KEY"; /* Get the SoundCloud UserId from the username */ $json = wp_remote_get("http://api.soundcloud.com/users/jwagener.json?client_id=".$soundcloud_playsAPI); $soundcloudData = json_decode($json['body'], true); $soundcloud_userid = $soundcloudData['id'];

This returns the UserId: 3207181

Now I tried to substitute that response into the previous URL to get the "playback_count" but it failed.

$json = wp_remote_get("http://api.soundcloud.com/tracks/3207181.json?client_id=".$soundcloud_playsAPI); $soundcloudPlaysData = json_decode($json['body'], true); echo $soundcloudPlaysData['playback_count'];

Any guidance would be greatly appreciated.



Here is the full solution:

function listPlays() {SC.initialize({ client_id: 'YOUR ID HERE'}); // Get the SoundCloud UserId from the username var userName="jwagener"; SC.get("/users/"+userName, function (users) {console.log(users.id); var myId=users.id; getTracks(myId); }); var getTracks=function (myId) {var totalPlays=0; SC.get("/users/"+myId+"/tracks", function(getTracks) {for (var key in getTracks) //get each track and look at it's playback_count {console.log(getTracks[key].title+" "+getTracks[key].playback_count); totalPlays+=getTracks[key].playback_count; //add the playback count for this track to the total } console.log("Total Plays for all tracks: "+totalPlays); }); }; };


The first number is the id of a track, the second number is the id of a user.

Now that you have the user id, you will need to fetch each of their tracks and tally how many times they have been played

First, get the id numbers for all tracks made by the user

GET: /users/{id}/tracks: list of tracks of the user

$json = wp_remote_get("http://api.soundcloud.com/users/3207181/tracks.json?client_id=".$soundcloud_playsAPI);

Now you have a list of track IDs so you will need to get each of those tracks and save the playback_count of each

$json = wp_remote_get("http://api.soundcloud.com/tracks/track-id-here.json?client_id=".$soundcloud_playsAPI); $soundcloudPlaysData = json_decode($json['body'], true); echo $soundcloudPlaysData['playback_count'];


  • How to run an R script and show a plot?
  • Batch script file name
  • Serverless Framework Dynamo DB Table Resource Definition with Sort Key
  • JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token
  • How to concat Pandas dataframe columns
  • How can I let users share their location in Bot Framework webchat channel?
  • Vuejs: Lifecycle hooks of child routerview components using keep alive
  • (Tcl/Expect) clear screen after exit
  • Android onKey w/ virtual keyboard
  • Django return user model id with L
  • how to get username into sql trigger when multiple users signed on from asp membership
  • extjs4 catching the scroll event on panel
  • chrome video src change not working
  • How can I run DataNucleus Bytecode Enhancer from SBT?
  • Repository Browser Only - \"Repository moved permanently to… please relocate”
  • CSS bleed-through with cfinput type=“datefield”
  • Group list of tuples by item
  • Tomcat memory Leak
  • Cannot upload to OneDrive using the new SDK
  • Graphics.CopyFromScreen [Web application] + The handle is invalid
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • MongoError: Incorrect arguments
  • Django rest serializer Breaks when data exists
  • C++ Partial template specialization - design simplification
  • Lost migrations and Azure database is now out of sync
  • Get one-time binding to work for ng-if
  • Dynamically accessing properties of knockoutjs observable array
  • Jenkins: How To Build multiple projects from a TFS repository?
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Cassandra Data Model
  • How can I estimate amount of memory left with calling System.gc()?
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Getting error when using KSoap library to consume .NET web services
  • Hits per day in Google Big Query
  • EntityFramework adding new object to nested object collection
  • How to get NHibernate ISession to cache entity not retrieved by primary key