That should be the output of
} else {
echo 'Failed with ' . $i['http_code'] . ' ' . $r;
}
So $r should have something. You have provided the output of $i which doesn’t contain the bit of info we need
You token generation for a client credentails token seems to have failed.