charlie86/spotifyr

INVALID_CLIENT: Invalid redirect URI

Closed this issue · 4 comments

I am trying this example and get the error: INVALID_CLIENT: Invalid redirect URI on the webpage that opens

library(lubridate)

get_my_recently_played(limit = 5) %>% 
    mutate(artist.name = map_chr(track.artists, function(x) x$name[1]),
           played_at = as_datetime(played_at)) %>% 
    select(track.name, artist.name, track.album.name, played_at) %>% 
    kable()

Is there something else I must configure to avoid this? Thanks.

@AtomicNess123 You are likely getting this issue when you are running the README.Rmd as knitr file, and you do not see the console messages. If you run chunk by chunk the the code, you will see that you will have to interact with the Spotify authentication process. First, you have to copy an authentication link to your browser, and second, you will get a Y/n question in your console.

I am trying to reference this somehow in the README.

Thanks, I was actually not running README.Rmd as knitr file.
I copied and pasted this into RStudio:

library(spotifyr)
Sys.setenv(SPOTIFY_CLIENT_ID = 'MYID')
Sys.setenv(SPOTIFY_CLIENT_SECRET = 'MYCLIENTSECRET')
access_token <- get_spotify_access_token()

library(tidyverse)
library(knitr)
beatles <- get_artist_audio_features('the beatles')
beatles %>% 
  count(key_mode, sort = TRUE) %>% 
  head(5) %>% 
  kable()

This works without problems.

Next I do:

#### Get your most recently played tracks
library(lubridate)
get_my_recently_played(limit = 5) %>% 
  mutate(artist.name = map_chr(track.artists, function(x) x$name[1]),
         played_at = as_datetime(played_at)) %>% 
  select(track.name, artist.name, track.album.name, played_at) %>% 
  kable()

And I get in the console:

Waiting for authentication in browser...
Press Esc/Ctrl + C to abort

The browser opens with the message: "INVALID_CLIENT: Invalid redirect URI".

You mentioned "First, you have to copy an authentication link to your browser, and second, you will get a Y/n question in your console." Could you explain how do I do this? Thanks so much for your help.

I had the same problem and in my case it was that I was not following step by step the readme: I skipped this section.

The main problem was that in the code for get_spotify_authorization_code the name of the app is hardcoded as 'spotifyr', so the app in your spotify api dashbord should have that same name.
I'm not sure about the URI, whether it needs to be identical as well or not. I've put the same just in case

EDIT:
or maybe not, because I've just remebered that I also installed the httpuv package, and I don't remember which one actually solved the problem

Thank you! Exactly that. I had skipped that part in the authorization setting. Now it's working!