And I have no idea how you copy/pasted that into your code, without looking at your code.
Since generate_and_maintain_token.php does not have a $token, it just print_r's
But if you put $data at line 62 into a variable called $token then sure, that sounds correct