Soundcloud API Auth via Golang 401 Error

前提是你 提交于 2019-12-02 05:47:03

I don't know if you got the authentication process right. At first, you need to set up an app on SoundCloud - you have done that, because you have a client secret and a client id.

Then you open the SoundCloud login page, enter your username and password, and then (if you're logged in successfully) you're redirected to the Redirect URI with the authorization code. That code is very important, because with that code you can obtain the access token.

If you put in

v.Set("grant_type", "authorization_code")

you also need to set the authorization code with:

v.Set("code", AUTHORIZATION_CODE)

After that you'll get a response from SoundCloud with the access token, refresh token and so on..

EDIT:

So, for example your Redirect URI looks like this

http://redirect.uri

then, when the user authenticated successfully, you'll get redirected to that URI including the authentication code. It will look like this:

http://redirect.uri/?code=AUTHENTICATION_CODE

Then you make a POST request to

https://api.soundcloud.com/oauth2/token

including your authentication code, client id and client secret. The response will include the access token, refresh token and so on.

I think you also need to set the client secret, not only your client id.

I also wanted a non-expiring access token, but somehow this is not working. So I'm refreshing my access token everytime it is expired.

Maybe you want to check this.

Go implementation of Soundcloud Oauth2

https://github.com/vitorsvvv/go-soundcloud-oauth

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