Spotify API 响应禁止我在当前播放的曲目请求中寻求定位



对于我想到的一个小项目,我想更好地了解Spotify API。一切都很顺利,直到我想尝试在当前播放的曲目请求中搜索定位,这只需要用户修改播放状态范围,当我发送请求时,服务器会响应403 FORBIDDEN。

{ [WebapiError: Forbidden] name: 'WebapiError', message: 'Forbidden', statusCode: 403 }

值得一提的是,我正在使用spotify-web-api-node模块与API通信,但我尝试从Postman发送相同的请求,并发生了相同的问题。

我使用此功能在用户之间切换:

const switchToUser = (username, callback) => {
User.findOne({ username: username })
.then(user => {
if (user !== null) {
SpotifyApi.setRefreshToken(user.refreshToken);
SpotifyApi.refreshAccessToken()
.then(data => {
SpotifyApi.setAccessToken(data.body["access_token"]);
callback(); // Callback
})
.catch(err => console.log(err));
} else {
console.log("There's no user with that username in the database.");
}
})
.catch(err => console.log(err));
};

我的电话:

switchToUser("stelrin", () => {
SpotifyApi.seek(1569091982344).then(
() => console.log("done"),
err => console.log(err)
);
});

授权链接:

https://accounts.spotify.com/authorize?client_id={myClientId}&response_type=code&redirect_uri={myRedirectUri}&scope=user-modify-playback-state%20user-read-playback-state&state=stelrin

查找功能:图像

我尝试在spotify-web-api-node文档中查找查找功能,但没有找到它。

谢谢你的时间。

您可以在尝试播放时获得 403 但没有高级版,但消息会说PREMIUM_REQUIRED,另一种可能性是 Seek 的参数不正确,仅支持position_msdevice_id,后者是选项,您可以尝试检查发送到 Spotify 的内容以检查对 https://api.spotify.com/v1/me/player/seek 的请求是否正确

最新更新