我认为这是API的错误。
sp = getSpotifyAPI(1);
models = sp.require('sp://import/scripts/api/models')
models.library.playlists;
> TypeError: Cannot read property 'length' of undefined
try { models.library.playlists } catch(err) { console.log(err.stack) }
> TypeError: Cannot read property 'length' of undefined
at map (sp:216:20)
at Library.<anonymous> (eval at evalModule (sp:55:46))
at unknown source
at Object._evaluateOn (unknown source)
at Object._evaluateAndWrap (unknown source)
at Object.evaluate (unknown source)
挖掘 models.js 文件,我们看到 Library 使用 sp.core.library.getPlaylists() 来获取播放列表,它应该返回一个数组但返回未定义:
sp.core.library.getPlaylists()
> undefined
sp.core.library.getPlaylists
> function getPlaylists() { [native code] }
由于 sp.core.library.getPlaylists 是本机代码,我无法深入兔子洞以查看它在做什么。因此,除非 spotify 开发人员说这是所需的行为,否则我的结论是这是一个错误。