问题
Code to replicate
In my app I have the following code.var seed = "spotify:artist:3UbyYnvNIT5DFXU4WgiGpP"; sp.core.getMetadata(seed, { onSuccess: function (metadata) { console.log(metadata); }, onFailure: function () {} });
Steps to view the behaviour
- If spotify is already open close it and then reopen it, after opening spotify run the app and view the console Which displays as
Object name: "Whitesnake" portrait: "" type: "artist" uri: "spotify:artist:3UbyYnvNIT5DFXU4WgiGpP" __proto__: Object
- Then click on the radio app and create a station based on the the band Whitesnake.
- Rerun the original app and view the console output which will display.
Object name: "Whitesnake" portrait: "spotify:image:3c4aa30d845dd456d750cf16bef8e2cadb2af342" type: "artist" uri: "spotify:artist:3UbyYnvNIT5DFXU4WgiGpP" __proto__: Object
- Quit spotify and rerun the original application and view the console which will display
Object name: "Whitesnake" portrait: "" type: "artist" uri: "spotify:artist:3UbyYnvNIT5DFXU4WgiGpP" __proto__: Object
Question
Why is the radio app able to access a portrait uri that is then accessible from my app after using the radio app? Is there some sort of initialization, that needs to be done first or is this a bug?
回答1:
Some information on an artist (and album, etc) isn't available until you do a "browse" on that URI - until then, Spotify only downloads basic information on an item to keep performance up.
What you're seeing is the Radio doing a browse, which causes the Spotify client to fill in the missing information.
An update to Spotify is coming soon that will improve this behaviour.
回答2:
If I understood you correctly, you've noticed that after you get the result with a portrait URI from the radio, you get that object data populated when using it in your app?
On another note; you should be using the Artist class instead of sp.core.
var sp = getSpotifyApi(1);
var models = sp.require('sp://import/scripts/api/models');
models.Artist.fromURI("spotify:artist:3UbyYnvNIT5DFXU4WgiGpP", function(album) {
console.log(album);
});
This should give you the correct output with a portrait uri string.
Artist
data: Object
name: "Whitesnake"
portrait: "spotify:image:3c4aa30d845dd456d750cf16bef8e2cadb2af342"
type: "artist"
uri: "spotify:artist:3UbyYnvNIT5DFXU4WgiGpP"
回答3:
As iKenndac mentioned, try doing a 'browse':
var seed = "spotify:artist:3UbyYnvNIT5DFXU4WgiGpP";
sp.core.browseUri(seed, {
onSuccess: function (metadata) {
console.log(metadata);
},
onFailure: function () {}
});
Examples here: https://github.com/ptrwtts/kitchensink
来源:https://stackoverflow.com/questions/8723471/possible-spotify-portrait-metadata-caching-bug