user login to api


I am working on a shiny app that uses the Spotify API to get data on a specific user's account. The app works perfectly within RStudio, but I get an error when I deploy to I think the error occurs because when I run it in RStudio, I automatically get redirected to Spotify's login page to sign into my account and retrieve my data, but this doesn't happen on the live page and it crashes.

Does anyone have any tips or know how I can add authorization or redirect the app to a login page on launch?

What package are you using to interact with the API?, if you are using spotifyr you can set your credentials as environmental variables.

Sys.setenv(SPOTIFY_CLIENT_ID = 'xxxxxxxxxxxxx')
Sys.setenv(SPOTIFY_CLIENT_SECRET = 'xxxxxxxxxxxxx') 
1 Like

I am using spotifyr and already had the env variables. I think the problem arises when I call for the access and authorization codes though. My goal was for a user to be able to login using their spotify account. I would then use that information to get playlists etc.

Sys.setenv(SPOTIFY_CLIENT_ID = "xxx")
Sys.setenv(SPOTIFY_CLIENT_SECRET = "xxx")

access_token <- get_spotify_access_token()
auth_token <- get_spotify_authorization_code(scope = scope)

Have you tried using. .Renviron and readRenviron? As in the following:

readRenviron(file.path("~", ".Renviron"))