【发布时间】:2018-03-29 03:22:12
【问题描述】:
我正在尝试使用 Node.js 和 Spotify Web API Node 的 Client Credential flow 获取 Spotify 访问令牌(仅包含客户端 ID 和客户端密码)。这是我的代码:
var SpotifyWebApi = require('spotify-web-api-node');
var spotifyApi = new SpotifyWebApi({
clientId : clientId, // my Client ID
clientSecret : clientSecret // my Client Secret
});
spotifyApi.clientCredentialsGrant()
.then(function(data) {
spotifyApi.setAccessToken(data.body['access_token']);
}, function(err) {
console.log('Something went wrong when retrieving an access token', err);
});
我遇到的问题是我总是收到以下错误:
TypeError: spotifyApi.clientCredentialsGrant is not a function
我可以毫无问题地访问这个库中的许多其他功能。例如,我可以这样写:
console.log(`The Client secret is ${spotifyApi.getClientSecret()}`);
console.log(`The Client ID is ${spotifyApi.getClientId()}`);
我在控制台中得到了预期的输出:
The Client secret is [my Client Secret]
The Client ID is [my Client ID]
有趣的是,通过使用 WebStorm 的代码完成,我可以看到许多其他可用的方法。事实上,我可以看到总共 88 种方法(甚至比列出的 here 还要多),但该列表中也缺少 clientCredentialsGrant()。
我认为这会相当简单,但我一定在某个地方犯了一个简单的错误。有没有人成功使用过这个方法?或者以前有人遇到过这个错误吗?我应该这样做有更好的方法吗?
【问题讨论】: