普通网友 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条)

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器