普通网友 2014-04-10 12:14
浏览 27
已采纳

Soundcloud和PHP:从访问令牌获取用户名的问题

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.

  • 写回答

2条回答 默认 最新

  • douchao1957 2014-04-18 05:37
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效