[英]How to get Spotify access token using Web API Node
I referred to the link https://www.npmjs.com/package/spotify-web-api-node我参考了链接https://www.npmjs.com/package/spotify-web-api-node
Code sample:代码示例:
var SpotifyWebApi = require('spotify-web-api-node');
// credentials are optional
var spotifyApi = new SpotifyWebApi({
clientId: 'fcecfc72172e4cd267473117a17cbd4d',
clientSecret: 'a6338157c9bb5ac9c71924cb2940e1a7',
redirectUri: 'http://www.example.com/callback'
});
In this how can I get the access token?在这种情况下,我如何获得访问令牌?
The specific code above will not return an access token.上面的特定代码不会返回访问令牌。 You'll need to refer to the "Authorization" section of that package where you can decide between the Authorization code flow or the Client Credential flow.
您需要参考该包的“授权”部分,您可以在其中决定是授权代码流还是客户端凭据流。 Both will return an access token but, depending on your use case, you will have to decide which is the best one for you.
两者都将返回一个访问令牌,但根据您的用例,您必须决定哪一个最适合您。
For Authorization code flow it looks something like this:对于授权代码流,它看起来像这样:
spotifyApi.authorizationCodeGrant(code).then(
function(data) {
console.log('The token expires in ' + data.body['expires_in']);
console.log('The access token is ' + data.body['access_token']);
console.log('The refresh token is ' + data.body['refresh_token']);
...more code
}
For the Client Credential flow it looks similar like this:对于客户端凭据流,它看起来像这样:
spotifyApi.clientCredentialsGrant().then(
function(data) {
console.log('The access token expires in ' + data.body['expires_in']);
console.log('The access token is ' + data.body['access_token']);
...more code
})
The Spotify Guide on Authorization would be a good resource to help make the decision of which path to follow. Spotify 授权指南将是一个很好的资源,可以帮助您决定要遵循的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.