« TikTok Data Scraper

TikTok API Music Scraper

Download Data to Excel & CSV Files

Steve Spagnola
Written by Steve Spagnola
Last updated March 28, 2022

Scrape & Monitor TikTok Music API Artists & Popularity

TikTok isn’t just the hottest social media network right now, but also a treasure trove of data surrounding the music industry for anyone wanting to identify popular & trending musical talent. With so much time spent on TikTok, it may now be a major venue for where people are listening to music.

While TikTok’s music libraries & data aren’t directly available, with some clever legwork we can use TikAPI, the unofficial TikTok API, as a music data API. TikAPI allows us to search for music and also gather music data from already popular videos on TikTok. We can then scrape details about these music tracks, like how many videos on TikTok are using the music, aggregate view counts, and more!

Sign Up for TikAPI

You can evaluate TikAPI for 5 days at no charge. Just visit their site and sign up, then you’ll receive an API key you can use to follow the rest of this article. You may also want to reach out to their customer support if you’re not comfortable providing payment information upfront and they can send you a free trial key like they did with us.

Disclaimer: We were provided with a free API key from TikAPI for the purposes of evaluating their service and writing this article, but we were not compensated in any other way to promote their service.

When someone posts on TikTok with a music track, it’s tagged to the post and assigned a “Music ID.” So if we’re interested in tracking how popular a musical artist is, we need to search for popular music tracks and get the corresponding Music ID(s) for the musical tracks. This can be done with the TikAPI Discover Music Endpoint which allows you to search for music tracks by keyword. Simply set the category to music (e.g. your URL will be https://api.tikapi.io/public/discover/music) and provide a keyword search for a music track. E.g. we can use selfish love as an example, but feel free to change this to your interpretation of good music.

In the response, you’ll see the results returned under musicInfoList and you’ll typically want to look at the first result (check to make sure it’s the music track you want and not hiding in 2nd place), then look for the music.id field - it will be a long number like 6834062462547954000 - copy this so we can use it next.

Scraping with Stevesie: If you need help accessing this endpoint to get the Music ID, you can use the TikAPI Discover Music Endpoint, which will query this endpoint on your behalf and let you quickly get the Music ID based on your search. You can also use our TikTok Discover Search Workflow to enter in a list of music search terms and download a bulk list of results all combined together. Note these are both paid services that we provide, separate from TikAPI.

Get Music Details & Video Count

Once you have the Music ID (or list of IDs), you can now look up details about each music item in addition to seeing the video count, or number of videos tagged with the music you’re tracking. To do this, simply access the TikAPI Music Information Endpoint and provide the Music ID as the id paramter to get back results. You’ll see the video count in the musicInfo.stats.videoCount field in the response. This will change over time (hopefully it won’t go down), and you can call this endpoint every day, week, month, etc… to track how many videos are tagging the piece of music in question.

Scraping with Stevesie: If you need help accessing this endpoint to get the Music Details & Video Count, you can use the TikAPI Music Details Endpoint, which will query this endpoint on your behalf and let you quickly get the music details based on your search. You can also use our TikTok Music Details - Multiple Music IDs Workflow to enter in a list of music IDs and download a bulk list of results all combined together. Note these are both paid services that we provide, separate from TikAPI.

Get TikTok Video Posts by Music ID

While knowing the total number of videos using your musical track is a good quantitative measure, you may also be interested in the qualitative properties of the content featuring the music you’re interested in. We can do this with the TikAPI Posts by Music Endpoint which allows us to provide a Music ID and will return a list of posts containing our music (presumably ordered by most popular & recent). These results will contain play counts, so in theory if you add all of these up together, you can track the play count of any Music ID, however in reality it’s impossible to get back ALL the results from this endpoint.

Simply execute the endpoint and provide your music ID under the id parameter and set count to 30 so you get as many results as possible back from TikAPI. To get the next page of results, you want to look in the response for cursor (it should be 30 if the count was set to 30), then provide it as the cursor input in the next request. This will return back the 2nd page of results (the response cursor field should now say 60) and you can keep repeating to get more posts tagging the music you’re interested in. Note that the results will never be exhaustive, but you should be able to get back a few hundred posts per music ID.

Scraping with Stevesie: If you need help downloading this data into a CSV file and don’t want to deal with writing code to handle pagination, you can use the TikTok Music Details - Multiple Music IDs Workflow which will allow you to enter a single Music ID (or a list of them), and the workflow will take care of pagination for you and combine all of the video post results (with stats about their play counts) into a single CSV file you can then analyze or upload into your own systems. Note this is a paid service that we provide, separate from TikAPI.

You will have access to copyrighted music and album art that you cannot legally display on your own website without facing copyright infringement consequences. While you’re most likely fine to use any scraped data for personal use, you will need to consult competent legal counsel if doing anything beyond this.