4

我正在尝试从笔记本电脑上的本地 HTML 页面访问 Soundcloud。我被困在将“callback.html”作为redirect_uri托管的部分。我尝试运行的脚本是 Soundcloud 文档页面中的基本身份验证 JavaScript:

<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
  client_id: 'my_client_id',
  redirect_uri: 'http://127.0.0.1/Users/Maria/Documents/SoundcloudClient/callback.html'
});

// initiate auth popup
SC.connect(function() {
  SC.get('/me', function(me) { 
    alert('Hello, ' + me.username); 
  });
});
</script>

当我在 Chrome 和 Firefox 中启动页面时,这个脚本让我进入连接弹出窗口。但是,一旦我以 Soundcloud 用户身份登录,就会收到以下错误:

Oops! Google Chrome could not connect to 127.0.0.1

如果我将我的 redirect_uri 更改为 localhost 我会得到同样的错误。

如果我尝试:

files:///C:/Users/Maria/Documents/SoundcloudThinClient/callback.html

我收到类似的错误。

我也试过:

ocalhost:3000

和:

localhost:8080

即使我不确定在这些端口上会监听什么。

所以,基本上,我在问我应该为 callback.html 放置什么路径才能使其正常工作?

我承认我不知道 redirct_uri 的实际功能。我查看了 Oauth 页面,但我不明白。我开始认为我不能简单地创建一个 HTML 页面、粘贴 JavaScript、创建一个 callback.html 文件并进行这项工作,即使 SC 文档似乎说这是可能的。如果是这样,我错过了哪些步骤?

4

2 回答 2

1

I am beginning to attempt this. I believe you have to go to the developer site and sign up as having an app. The redirect uri is asked for and the form gives you an API key you can use in your app.

I'm using drupal so, perhaps adding the oath module and using Php to add the api key might work well.

于 2012-11-13T02:53:58.860 回答
1

我有同样的问题,我想我解决了。

编辑后的早晨:我在通宵努力解决问题后发布了这个累死人的帖子。现在,后天,我意识到你说的是一般问题,而我面临一个非常特殊的例子。以下仅适用于注册 soundcloudlabs 的soundcloud-group-recorderhttps://github.com/soundcloudlabs/soundcloud-group-recorder。不过,这背后可能隐藏着一个更普遍的原则:

首先:是的,您必须在 Soundcloud 上将应用程序注册为您自己的应用程序。至少我是这么认为的。这样做,您必须正确注册您将在服务器上放置 callback.html 文件的位置。获取分配给您的应用程序的ClientID并在 API 初始化过程中使用它。

现在,我是一个新手,对编码知之甚少。但我开始查看主文件 application.js。

  1. 在文件的顶部,每个都有两个client_idredirect_uri实例。我不确定这是否有目的,或者是否在技术上是多余的。通过反复试验,我发现用我自己的数据替换每个实例的第二个实例是有效的。

  2. 然后是groupIdgroupUrl,它们都应该包含您的信息,用引号括起来。

  3. 经过大量的试验和错误后,仍然无法让程序运行,我环顾四周,发现,在文件的早期,client_id被挂在 SC.initialize 中,redirect_uri没有。下线:

client_id: CLIENT_ID

我补充说:

redirect_uri: REDIRECT_URI

– 中间有一个习惯性的逗号。就是这样。它运行。

于 2014-05-25T05:34:03.963 回答