Question

I can't get the country code from the Session, apparently, if I refer to Spotify API 1.x get user session, it is simple as:

require(['$api/models','$api/library#Library'], function(models,Library) {

  console.log("country=" + models.session.country);

});

It is 'undefined'

What am I doing wrong?

I use api :

"api": "1.38.0"

"views": "1.18.1"

Was it helpful?

Solution

With very few exceptions, you need to load properties for them to be available on your Spotify object. This is done for performance reasons.

Load the country property on the session object like so:

require(['$api/models'], function(models) {
  var session = models.session;
  session.load("country").done(function() {
    console.log("country=" + session.country);
  });
});

The load function is documented briefly here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top