how to generate soundcloud oauth token (access token)

浪尽此生 提交于 2021-02-07 10:50:30

问题


I have an asp.net web application where I am trying to upload tracks on Soundcloud using this method: Connecting to and uploading tracks with Soundcloud API using C# .NET

I created an app on soundcloud but I don't know how to generate my oauth token [oauth_token]

Thanks


回答1:


The oauth token is something you get per user after they authorize your app. For server-side web applications, you use the API credentials for your app to redirect the user to the SoundCloud authorization URL so they can login and approve your request.

When they approve your authorization request, they are sent to the redirect_uri you specified when registering your app. There is a code in this response (code in the querystring) that you will exchange for the oauth token you want (in this case its called access_token). Then you need to save off that access_token (associated with that user).

I recently created a SO post with C# code detailing how to do this: How to let users login to my site using SoundCloud. You can also use this as an authentication method for your website (also what the post is about).




回答2:


You don't generate it on yourself, you get it from the SoundCloud API. You have first to authorize with your client_id, client_secret and a redirect_url then in the redirect_url (which the soundcloud server will call it should be some script on your server) you can get the token from the GET parameter "code". Then in the next step you can exchange the code for an access token.

Here is their example code in PHP:

<?php
// start.php
require_once 'Services/Soundcloud.php';

// create client object with app credentials
$client = new Services_Soundcloud('CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URL');

<?php
// callback.php
// exchange authorization code for access token
$code = $_GET['code'];
$access_token = $client->accessToken($code);


来源:https://stackoverflow.com/questions/13153177/how-to-generate-soundcloud-oauth-token-access-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!