简体   繁体   English

Soundcloud身份验证和API

[英]Soundcloud Authentication and API

I am new to soundcloud. 我是soundcloud的新手。 I have done my research but the soundcloud documentation is lacking severely. 我做了我的研究,但soundcloud文档缺乏严重性。

I am trying to understand the API. 我想了解API。 If anyone can help answer the following questions it would be helpful. 如果有人可以帮助回答以下问题,那将会很有帮助。

  1. Can I access my tracks through the JavaScript API and retrieve JUST the titles of the tracks? 我可以通过JavaScript API访问我的曲目并检索曲目的标题吗?

  2. Where do I get my "User ID" from? 我从哪里获得“用户ID”?

  3. I have created an app. 我创建了一个应用程序。 Is the Redirect URI mandatory? 重定向URI是否必需?

  4. I have tried to use the following https://api.soundcloud.com/tracks?client_id=MY_CLIENT_ID . 我尝试使用以下https://api.soundcloud.com/tracks?client_id=MY_CLIENT_ID I get some other members information. 我得到一些其他会员的信息。 And yes I replaced MY_CLIENT_ID with the client_id from my new app. 是的,我用我的新应用中的client_id替换了MY_CLIENT_ID。

  5. I have tried to use https://api.soundcloud.com/oauth2/token?client_id=xxx&client_secret=xxx&grant_type=password&username=xxx&password=xxx (with my app client_id, client_secret, username & password and I get a 404...not sure why. 我曾尝试使用https://api.soundcloud.com/oauth2/token?client_id=xxx&client_secret=xxx&grant_type=password&username=xxx&password=xxx (使用我的app client_id,client_secret,用户名和密码,我得到404 ...不确定为什么。

Any response to put me in the right direction would be great. 任何让我走向正确方向的回应都会很棒。 Thanks! 谢谢!

Can I access my tracks through the JavaScript API and retrieve JUST the titles of the tracks? 我可以通过JavaScript API访问我的曲目并检索曲目的标题吗?

No, there's no way of retrieving only the titles, you'll get the whole sound representation in JSON or XML depending on the format parameter sent in request. 不,没有办法只检索标题,你将获得JSON或XML中的整个声音表示,具体取决于请求中发送的format参数。

Where do I get my "User ID" from? 我从哪里获得“用户ID”?

You could use /resolve endpoint to retrieve an ID from the permalink of the user, yours or any other or, if you authorised the user, you could hit /me endpoint to get the representation of the authorised user. 您可以使用/resolve端点从用户,您或其他任何人的固定链接中检索ID,或者,如果您授权用户,则可以命中/me端点以获取授权用户的表示。

I have created an app. 我创建了一个应用程序。 Is the Redirect URI mandatory? 重定向URI是否必需?

Yes

I have tried to use the following https://api.soundcloud.com/tracks?client_id=MY_CLIENT_ID . 我尝试使用以下https://api.soundcloud.com/tracks?client_id=MY_CLIENT_ID I get some other members information. 我得到一些其他会员的信息。 And yes I replaced MY_CLIENT_ID with the client_id from my new app. 是的,我用我的新应用中的client_id替换了MY_CLIENT_ID。

client_id is an id for your application, which is the “client” of SoundCloud API (which is the “server” in this case), your user is something else. client_id是应用程序的id,它是SoundCloud API的“客户端”(在这种情况下是“服务器”),您的用户是其他东西。 If you are talking about “authorised” user when referring to “my client id”, then you could query /me/tracks for the tracks that belong to that user. 如果您在提及“我的客户端ID”时正在谈论“授权”用户,那么您可以查询/me/tracks属于该用户的曲目。

I have tried to use https://api.soundcloud.com/oauth2/token?client_id=xxx&client_secret=xxx&grant_type=password&username=xxx&password=xxx (with my app client_id, client_secret, username & password and I get a 404...not sure why. 我曾尝试使用https://api.soundcloud.com/oauth2/token?client_id=xxx&client_secret=xxx&grant_type=password&username=xxx&password=xxx (使用我的app client_id,client_secret,用户名和密码,我得到404 ...不确定为什么。

Please follow the documentation for oauth2 endpoint – the request should be POST and not GET and you need to submit code parameter, value for which you'd get from the code that would run on your Redirect URI – after user successfully signs in that URL will be requested with code as GET parameter, so you can use it. 请遵循oauth2端点的文档 - 请求应该是POST而不是GET,并且您需要提交code参数,您可以从您的重定向URI上运行的代码中获取该值 - 用户成功登录该URL后请使用code作为GET参数,以便您可以使用它。

Addition to @gryzzly answer. 除了@gryzzly的回答。 You can access API without token, but you will get it only to your account. 您可以在不使用令牌的情况下访问API,但只能访问您的帐户。

As you can see here , there is an option for username/password authorization, and here you can see example, how to do it using SDK. 正如您在此处看到的,有一个用户名/密码授权选项, 在这里您可以看到示例,如何使用SDK执行此操作。

When you do your POST request, do all your parameters in the body of the post request: 当您执行POST请求时,请在post请求的正文中执行所有参数:

wget --post-data="client_id=ID&client_secret=SECRET&grant_type=password&username=USERNAME&password=PASSWORD" https://api.soundcloud.com/oauth2/token

Here is the PHP request example: 这是PHP请求示例:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.soundcloud.com/oauth2/token");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "client_id=ID&client_secret=SECRET&grant_type=password&username=USERNAME&password=PASSWORD");
$result = curl_exec($ch);
curl_close($ch);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM