Retrieve Video List from the official TikTok APIs


The TikTok PHP SDK has been updated, and the new v0.2 brings support for retrieving the User’s Videos.

If you’re new to the TikTok PHP SDK, please read my previous tutorial on how to log in and receive the Access Token. In that article, I also provide a bit of backstory and more general information about the TikTok Login Kit APIs for Web.

Once you’re all caught up and know how to log in and retrieve the access Token, retrieving the Videos is blazing fast.

The easiest way is to use the getUserVideoPages helper method, since it provides built-in pagination.

This will return an array that contains all the videos of the logged in user. Watch out because this will keep looping and calling the APIs for all the videos you have. So you might want to add the max_pages parameter. For example to limit to the latest 10 pages only:

If you want more control over the pagination, you can use the higher-level getUserVideos which allows you to manage your own pagination via the cursor and num_results parameters. For example, let’s say you only want the latest video:

The pagination info is provided in the cursor and has_more returned values. Here’s how you can implement your own pagination:

Once you have your $videos you can use the simple getter methods, e.g. getCoverImageURL to get all the available parameters.

Here’s a quick sample, populating a table

All done! If you have any suggestion on the class or its implementation please feel free to reach out on GitHub or Twitter.

Co-founder @Lnk.Bio — Developing stuff on the Web since 2003