Question

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\r\n";
$client = new Services_Soundcloud('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'YYYYYYYYYYYYYYYYYYYYYYYYYYYY', 'http://ZZZZZZZZZZZZZZZZZZZZZZZZZZ/soundcloud_ut.php');
echo "After client init\r\n";
// exchange authorization code for access token
$code = $_GET['code'];
echo "After get code\r\n";
$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.

Was it helpful?

Solution 2

The problem was my development environment. There was a couple of problems:

  1. cURL for PHP needs to be installed (in Ubuntu: apt-get install php5-curl).
  2. json for PHP needs to be installed (in Ubuntu: apt-get install php5-json).

I needed to upgrade from Ubuntu 12.04 to Ubuntu 13.10 to correctly install json for PHP.

After installing curl and json it worked as expected.

OTHER TIPS

Change " -> " to " = "

$user = json_decode($client->get('me'));
print $user->username;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top