简体   繁体   English

如何使用 Web API 节点获取 Spotify 访问令牌

[英]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.

相关问题 仅使用客户端凭据获取 Spotify 访问令牌(Spotify Web API 节点) - Getting a Spotify access token using only client credentials (Spotify Web API Node) 使用spotify-web-api-node生成身份验证令牌 - Using spotify-web-api-node to generate an authentication token 如何使用 Axios 使用 Node js API 获取 Azure 访问令牌 - How to get Azure access token with Node js API using Axios 尝试使用访问令牌访问Spotify Web API时获取401 - Getting 401 when trying to access spotify web api with access token 我应该何时以及如何在 Node.Js 中刷新我的 Spotify API 访问令牌 - When and how should I refresh my Spotify API access token in Node.Js Spotify Api Ajax Post请求使用“ ajax-request”节点包获取令牌 - Spotify Api Ajax Post request to get token using the 'ajax-request' node package 来自spotify-web-api-node调用的访问响应头 - Access Response Headers from spotify-web-api-node call 如何存储 Spotify api 的访问令牌。 我正在使用passport.js - How to store the access token for Spotify api. I am using passport.js 如何从节点脚本获取 Microsoft Graph API 访问令牌? - How to get Microsoft Graph API Access token from Node Script? 如何获取Google网站管理员api(Node.js)的访问令牌 - How to get access token for google webmasters api (Node.js)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM