njasm / laravel5-soundcloud

Soundcloud API Service Provider For Laravel 5
MIT License
15 stars 9 forks source link

OutOfBoundsException in Response.php line 87: Last Request Content-Type isn't application/json. #12

Closed RobbeVW closed 8 years ago

RobbeVW commented 8 years ago

I'm getting this error after I go to the getIndex() function. I believe I did everything right. Here's my code: https://gist.github.com/glowdemon1/8caccb50599af41b2353b5eca3ac3452 - did I do anything wrong or is this a bug?

njasm commented 8 years ago

Tell me the requests order/flow of your controller to replicate the error. Login() -> PostLogin() -> Index() ?

show me the values of your: SOUNDCLOUD_CALLBACK_URI and SOUNDCLOUD_AUTO_CONNECT

add a try catch to the line that throws and var dump me the response object .

RobbeVW commented 8 years ago

That flow is correct.

SOUNDCLOUD_CALLBACK_URL=http://localhost:8000/post-login SOUNDCLOUD_AUTO_CONNECT=false

The problem was that I kept getting 401 'unauthorized' errors. I played around with the code and got a working result (https://gist.github.com/glowdemon1/8caccb50599af41b2353b5eca3ac3452/revisions). Right now I need to re-login each time I refresh getIndex() strangely. If you happen to know the issue with that, please let me know. Thanks.

njasm commented 8 years ago

ok, nice you have a working code... but first:

  1. Your callback_uri is wrong, I wonder how does soundcloud.com find your callback URI (cos it's set to localhost) when they provide you the code? you have a proper resolvable domain name right?
  2. In the getIndex() you need to call codeForToken($code), and if successful you call $accessToken = Soundcloud::getAuthToken() and store it on the user's session so you can add it for future request of your user while his session's active and valid on your website.

On future requests from your user, you grab his/her token, and if valid, before any call to soundcloud you do Soundcloud::setAccessToken($accessToken) and call the methods you want after.. everything should work as expected.

try it out and tell me how it went.

RobbeVW commented 8 years ago

http://prntscr.com/bqubcx this is the value of my redirect url at the SC app configuration, it works fine somehow.

Thanks for the info. I got it to work fine now. Here's the working code, if anyone's interested. https://gist.github.com/glowdemon1/8caccb50599af41b2353b5eca3ac3452

njasm commented 8 years ago

that's the trick https://gist.github.com/glowdemon1/8caccb50599af41b2353b5eca3ac3452#file-pagescontroller-php-L15

Glad to help out.