想从soundcloud api的SC.get()函数中获取用户名

时间:2012-04-28 13:06:23

标签: javascript soundcloud

我希望在成功连接到soundcloud之后获得soundcloud的用户名...我能够连接但没有获得soundcloud用户的用户名

<script type="text/javascript">

  $(document).ready(function() {
      SC.initialize({
          client_id: '****',
          redirect_uri: '***'
      });

  $('#connect').click(function(){
          SC.connect(function() {
              SC.get('/me', function(data) {
                  $('#name').text(data.username);
              });
          });
      });
  });

  </script>

</head>

<body>

<input type="image" src="images/larger-connect-with-sc.png" id="connect" />
<p>
Logged in as: <span id="name"></span>
</p>

2 个答案:

答案 0 :(得分:0)

一切看起来都不错。这里有一些修剪过的,但是可以用来比较的完整源代码:

<!doctype html>
<html>
  <head>
  <title>Example Two</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <script src="http://connect.soundcloud.com/sdk.js"></script>
  <script>
  $(document).ready(function() {
    SC.initialize({
      client_id: '8d720a0f46531b275c7c9a82619c9d46',
      redirect_uri: 'http://demo.paulosman.me/callback.html'
    });

    $('#connect').click(function() {
      SC.connect(function() {
        SC.get('/me', function(data) {
          $('#name').text(data.username);
        });
      });
    });
  });
  </script>
  </head>
  <body>
    <input type="image" src="images/larger-connect-with-sc.png" id="connect" />
    <p>
      Logged in as: <span id="name"></span>
    </p>
  </body>
</html>

您可以看到一个有效的例子here

如果有效,请告诉我。

答案 1 :(得分:0)

<body onload="window.opener.setTimeout(window.opener.SC.connectCallback, 1)"> <b style="width: 100%; text-align: center;">This popup should automatically close in a few seconds</b> </body>