Get Scrobble Information from Trakt.TV

This post is over a year old, the information may no longer be up to date.

This post was migrated from an old custom CMS. Some data may not look accurate.

Trakt is a platform that keeps track of TV Shows and Movies that you watch. You can integrate it into a bunch of different Media Center applications such as Plex or Kodi to automate scrobbling, via the Trakt website or via Mobile Apps.

I’ve been a user of Trakt since around 2013 and I absolutely love being able to look back on my yearly review of what I watched during each year and seeing how my love of movies and tv shows has changed genre over the years.

I made a script to grab my scrobble information from Trakt a few years ago but lost it in the depths of time up until recently, I uploaded it to GitHub not long after adding some comments to it so it makes some sense. I do want to warn you though, that it’s some quite impressive spaghetti code. You can view the code here.

If you’re looking to do this yourself without using a pre-existing script, here’s a basic example to get you started.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
    $user = "laim";
    $key = "";
    $type = "history"; //history or watching

    // You need to register an API app here https://trakt.tv/oauth/applications to get the API Key (ClientID)

    function traktAPI($user, $key, $type) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.trakt.tv/users/$user/$type");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Content-Type: application/json",
        "trakt-api-version: 2",
        "trakt-api-key: $key"
    ));
    $response = curl_exec($ch);
    curl_close($ch);
    return json_decode($response, true);
    }

    var_dump(traktAPI($user, $key, $type));
?>