mirror of
https://github.com/jwilsson/spotify-web-api-php.git
synced 2026-04-26 23:45:49 +03:00
[GH-ISSUE #29] Invalid authorization code #13
Labels
No labels
bug
docs
enhancement
enhancement
enhancement
feedback wanted
good first issue
help wanted
help wanted
help wanted
invalid
pull-request
question
question
upstream
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotify-web-api-php#13
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @matthijsotterloo on GitHub (Mar 29, 2015).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/29
Hi
I'm having a problem....
https://beta.cloudmoosic.com/music/spotify/login
After login I'm getting the Invalid Authorization Code Error, I've used the examples you gave but it's still not working....
Any idea on how to fix this?
@hvt commented on GitHub (Mar 29, 2015):
What example are you using exactly?
@matthijsotterloo commented on GitHub (Mar 29, 2015):
This is my code:
https://gist.github.com/matthijsotterloo/da9da7a90214cfbf9ab0
@jwilsson commented on GitHub (Mar 29, 2015):
Hi,
Everything works fine for me when I test your code locally.
It looks like you're using CodeIgniter, could the framework interfere with the $_GET parameter?
@matthijsotterloo commented on GitHub (Mar 29, 2015):
Ahh, thats the problem!
Any idea how I can fix it?
@hvt commented on GitHub (Mar 29, 2015):
I don't know anything about CodeIgniter, but it appears you have to replace
$_GET['code']with$this->input->get('code').@matthijsotterloo commented on GitHub (Mar 29, 2015):
Still the same error
@jwilsson commented on GitHub (Mar 29, 2015):
I'm not very familiar with CodeIgniter either, but the docs might be of some help: https://ellislab.com/codeigniter/user-guide/libraries/input.html
It looks like this might work:
$this->input->get('code', TRUE);@matthijsotterloo commented on GitHub (Mar 29, 2015):
Not working... Running in to a new error now,
Fatal error: Uncaught exception 'SpotifyWebAPI\SpotifyWebAPIException' with message 'Invalid client' in /home/cloudmoosic/www/beta.cloudmoosic.com/application/modules/music/controllers/vendor/Request.php:139 Stack trace: #0 /home/cloudmoosic/www/beta.cloudmoosic.com/application/modules/music/controllers/vendor/Request.php(26): SpotifyWebAPI\Request->send('POST', 'https://account...', Array, Array) #1 /home/cloudmoosic/www/beta.cloudmoosic.com/application/modules/music/controllers/vendor/Session.php(229): SpotifyWebAPI\Request->account('POST', '/api/token', Array) #2 /home/cloudmoosic/www/beta.cloudmoosic.com/application/modules/music/controllers/spotify.php(23): SpotifyWebAPI\Session->requestAccessToken('AQAakd0ztViyK4L...') #3 /home/cloudmoosic/www/beta.cloudmoosic.com/system/core/CodeIgniter.php(250): include('/home/cloudmoos...') #4 /home/cloudmoosic/www/beta.cloudmoosic.com/index.php(232): require_once('/home/cloudmoos...') #5 {main} thrown in /home/cloudmoosic/www/beta.cloudmoosic.com/application/modules/music/controllers/vendor/Request.php on line 139
@jwilsson commented on GitHub (Mar 29, 2015):
Looks like something's wrong with your app credentials, invalid client ID, wrong redirect URI etc.
@matthijsotterloo commented on GitHub (Mar 30, 2015):
Yea I see, any idea on how to integrate it with codeigniter? :(
@hvt commented on GitHub (Mar 30, 2015):
What's your current code?
-- Harm
On Mon, Mar 30, 2015 at 4:26 PM, Matthijs Otterloo <notifications@github.com
@matthijsotterloo commented on GitHub (Mar 30, 2015):
load->helper('url'); } public function login() { require_once 'vendor/Request.php'; require_once 'vendor/Session.php'; require_once 'vendor/SpotifyWebAPI.php'; require_once 'vendor/SpotifyWebAPIException.php'; $session = new SpotifyWebAPI\Session( '6428226f8930472080acde29db277e37', '73aec018a2724fe1985fc88130b44c86', 'https://beta.cloudmoosic.com/music/spotify/login' ); $scopes = array( 'user-read-email', 'user-library-modify' ); $api = new SpotifyWebAPI\SpotifyWebAPI(); // Redirect to Spotify login screen if user is not logged in. if (isset($_GET['code'])) { $session->requestAccessToken($_GET['code']); $accessToken = $session->getAccessToken(); // Set the access token on the API wrapper $api->setAccessToken($accessToken); // Request a access token using the code from Spotify print_r($api->me()); } else { $authorizeUrl = $session->getAuthorizeUrl(array( 'scope' => $scopes )); header('Location: ' . $authorizeUrl); die(); } } ``` }@jwilsson commented on GitHub (Mar 30, 2015):
Try adding a trailing slash to the redirect URI, i.e. https://beta.cloudmoosic.com/music/spotify/login/. Both in your app's settings at https://developer.spotify.com/my-applications/ and in your code.
@matthijsotterloo commented on GitHub (Mar 30, 2015):
Still
@jwilsson commented on GitHub (Mar 30, 2015):
I'm running out of ideas here. Have you tried creating a brand new app and using those credentials instead? (which you should anyway since your secret is now out in the open)
@hvt any ideas?
@hvt commented on GitHub (Apr 1, 2015):
Try: https://gist.github.com/hvt/b1ec30ece40e2fdd872c (of course with the appropriate client ID and client secret)
I really bet it's the trailing slash in your 'redirect URI' (i.e. the
Sessionconstructor's third argument). And like @jwilsson says, be sure this trailing slash is both in the code, and at the Spotify application page.@matthijsotterloo commented on GitHub (Apr 1, 2015):
@hvt Still the same problem....
@hvt commented on GitHub (Apr 1, 2015):
What about this?
https://gist.github.com/hvt/b1ec30ece40e2fdd872c
@matthijsotterloo commented on GitHub (Apr 1, 2015):
@hvt Unable to load the requested file: helpers/input_helper.php
@hvt commented on GitHub (Apr 1, 2015):
Now I'm out of options too...
I guess there's truly something wrong with your client ID, client secret, and redirect URL + what information you supplied to Spotify.
@jwilsson commented on GitHub (Apr 1, 2015):
Seems like the
inputhelper doesn't exist. I removed it, try this: https://gist.github.com/jwilsson/305ce1bfc740e1f50687@matthijsotterloo commented on GitHub (Apr 1, 2015):
@jwilsson Yes and now?
@jwilsson commented on GitHub (Apr 1, 2015):
What's your error now?
We're gonna need you to work a bit with us here :)
Have your tried creating a new app at https://developer.spotify.com/my-applications/ and setting your redirect URI to https://beta.cloudmoosic.com/music/spotify/login/ (with a trailing slash) and updating your code with the new credentials?
@matthijsotterloo commented on GitHub (Apr 1, 2015):
@jwilsson Lol maybe :p
Error is still the same! Yes I already did, this is the error again:
Fatal error: Uncaught exception 'SpotifyWebAPI\SpotifyWebAPIException' with message 'Invalid authorization code' in /home/cloudmoosic/www/beta.cloudmoosic.com/application/modules/music/controllers/vendor/Request.php:139 Stack trace: #0 /home/cloudmoosic/www/beta.cloudmoosic.com/application/modules/music/controllers/vendor/Request.php(26): SpotifyWebAPI\Request->send('POST', 'https://account...', Array, Array) #1 /home/cloudmoosic/www/beta.cloudmoosic.com/application/modules/music/controllers/vendor/Session.php(229): SpotifyWebAPI\Request->account('POST', '/api/token', Array) #2 /home/cloudmoosic/www/beta.cloudmoosic.com/application/modules/music/controllers/spotify.php(40): SpotifyWebAPI\Session->requestAccessToken('AQDhUZNV5IMYHWF...') #3 [internal function]: Spotify->login() #4 /home/cloudmoosic/www/beta.cloudmoosic.com/system/core/CodeIgniter.php(360): call_user_func_array(Array, Array) #5 /home/cloudmoosic/www/beta.cloudmoosic.com/index.php(232): require_once('/home/cloudmoos...') #6 {main} thrown in /home/cloudmoosic/www/beta.cloudmoosic.com/application/modules/music/controllers/vendor/Request.php on line 139
@jwilsson commented on GitHub (Apr 1, 2015):
The second argument to
$this->input->get('code')have gone missing, I've added it back here:https://gist.github.com/jwilsson/305ce1bfc740e1f50687
@matthijsotterloo commented on GitHub (Apr 1, 2015):
@jwilsson That's not fixing the error
@jwilsson commented on GitHub (Apr 3, 2015):
I really don't know where the error is coming from. It seems like CodeIgniter is doing something funky which is out of our control.
I'm closing this for now since it isn't a bug in the library.