New to Soundcloud and trying to get the username using the access token after the user logged in.
The process is:
The entry point is http://example.com/soundcloud_authenticate.php:
<?php
require_once 'Services/Soundcloud.php';
// create client object with app credentials
$client = new Services_Soundcloud(
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY', 'http://ZZZZZZZZZZZZZZZZZZZZZZZZZZZ/soundcloud_ut.php');
// redirect user to authorize URL
header("Location: " . $client->getAuthorizeUrl());
?>
Then the user get the Soundcloud authentication screen. After successful authentication, the user gets redirected to http://example.com/soundcloud_ut.php:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
require_once 'Services/Soundcloud.php';
// create client object with app credentials
echo "Before client init
";
$client = new Services_Soundcloud('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY', 'http://ZZZZZZZZZZZZZZZZZZZZZZZZZZ/soundcloud_ut.php');
echo "After client init
";
// exchange authorization code for access token
$code = $_GET['code'];
echo "After get code
";
$access_token = $client->accessToken($code);
$user->json_decode($client->get('me'));
echo $user->username;
?>
</body>
</html>
The problem is that the authentication works, and the redirect to soundcloud_ut.php works:
This is the response:
Before client init After client init After get code
But I do not get the $user->username.
Any help will be appreciated.