Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_my_saved_tracks issue #152

Closed
tom-pham opened this issue Jun 18, 2021 · 2 comments
Closed

get_my_saved_tracks issue #152

tom-pham opened this issue Jun 18, 2021 · 2 comments
Assignees
Labels

Comments

@tom-pham
Copy link

Apologies if I'm doing something obviously wrong but I was having issues with get_my_saved_tracks(). I'm on R 4.1.0 and spotifyr 2.2.1.

library(tidyverse)
library(spotifyr)
library(lubridate)

Sys.setenv(SPOTIFY_CLIENT_ID = my_client_id)
Sys.setenv(SPOTIFY_CLIENT_SECRET = my_client_secret)

access_token <- get_spotify_access_token()
get_my_saved_tracks()

Calling get_my_saved_tracks() returns the error:

The type parameter must be either 'artists' or 'tracks'

Looking through the source for get_my_saved_tracks() , I see that validate_parameters() requires a value for:

  • artists_or_tracks
  • artist_or_user

I tried copying the source code and editing it to see if I could get it to work. Within the validate_parameter() call I set

  • artists_or_tracks = 'tracks'
  • artist_or_user = 'artist'

Ran it again and got the following error:

Error: "country" must be an ISO 3166-1 alpha-2 country code.

Strange because it says country should be optional. Ok so now I set:
country = 'us'

Rain it again and got the following error:

Error: The parameter 'locale' must be an ISO_639-1 code as a character variable.

Also should have been optional. Change it to:
locale = 'eng'

Re-run, now I get

Error in RETRY("GET", base_url, query = params, config(token = authorization), : could not find function "RETRY"

Looks like RETRY() comes from httr. Load library(httr) and try again.

Error in fromJSON(content(res, as = "text", encoding = "UTF-8"), flatten = TRUE) : could not find function "fromJSON"

Looks like fromJSON is from jsonlite. Load library(jsonlite and try again. And voila! Seems to work now.

So basically this is all to say get_my_saved_tracks() did not work for me until I made these edits.

This is what I did to get it to work

library(spotifyr)
library(httr)
library(jsonlite)

get_my_saved_tracks <- function (limit = 20, offset = 0, market = NULL, 
                                 authorization = get_spotify_authorization_code(), 
                                 include_meta_info = FALSE) 
{
  validate_parameters(market = market, limit = limit, offset = offset, 
                      include_meta_info, artists_or_tracks = 'tracks',
                      artist_or_user = 'artist', country = 'us', 
                      locale = 'eng')
  base_url <- "https://api.spotify.com/v1/me/tracks"
  params <- list(limit = limit, offset = offset, market = market)
  res <- RETRY("GET", base_url, query = params, config(token = authorization), 
               encode = "json")
  stop_for_status(res)
  res <- fromJSON(content(res, as = "text", encoding = "UTF-8"), 
                  flatten = TRUE)
  if (!include_meta_info) {
    res <- res$items
  }
  res
}

get_my_saved_tracks()
@antaldaniel antaldaniel self-assigned this Jun 18, 2021
@antaldaniel
Copy link
Collaborator

@pham-thomas I think that this is a validation report, and simpler than you describe, but I'll fix it in the next devel version. validate_parameters() does not require both parameters, in fact, it does not require them at all. But I am sure that this is a parameter validation error. Thanks for the report!

antaldaniel added a commit to antaldaniel/spotifyr that referenced this issue Jun 18, 2021
@antaldaniel
Copy link
Collaborator

Try 2.2.2, this is fixed. It was a very simple error, the wrong parameter was sent to the assertion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
New major CRAN release
Awaiting triage
Development

No branches or pull requests

2 participants