I'm trying to write an R package that can be run in a headless environment like Github Actions. Using httr you can authenticate with the Spotify API in an interactive session with the below code (stolen from spotifyr
)
get_spotify_authorization_code <- function(
client_id = Sys.getenv("SPOTIFY_CLIENT_ID"),
client_secret = Sys.getenv("SPOTIFY_CLIENT_SECRET"),
scope = get_scopes()
) {
endpoint <- oauth_endpoint(authorize = 'https://accounts.spotify.com/authorize',
access = 'https://accounts.spotify.com/api/token')
app <- oauth_app('spotty', client_id, client_secret)
token <- safely(.f=oauth2.0_token)(
endpoint = endpoint,
app = app,
scope = scope)
if (!is.null(token$error)) {
token$error
} else {
token$result
}
}
When you first run this it pops open a browser window to authenticate. This only needs to be done once, and then uses refresh tokens from then on.
Is there a way I can adapt this so it doesn't use web-application-flow
and uses some other type of Auth that can be run headless. I know there is the 'client credentials flow', but it doesn't allow access to user resources and I'd like to be able to access things like saved playlists (i.e., the me
endpoint, 'https://api.spotify.com/v1/me/tracks/'
)