【发布时间】:2017-10-22 12:53:10
【问题描述】:
我正在学习如何使用 ReactJS、Spotify API 和 Promise。我正在尝试在 Spotify 上获取音乐家的热门专辑并播放 30 秒的曲目。
我正在使用一个名为 spotify-web-api-node 的 Spotify 包,我想我不了解 React 或 JS 的一些基本知识。 Syntax error: Unexpected token, expected ( (11:8)
从“反应”导入反应;
import SpotifyWebApi from 'spotify-web-api-node';
require('dotenv').config();
export default class SpotifyComponent extends React.Component {
// Create the api object with the credentials
const spotifyApi = new SpotifyWebApi({
clientId : process.env.REACT_APP_SPOTIFY_CLIENT_ID,
clientSecret : process.env.REACT_APP_SPOTIFY_CLIENT_SECRET
});
// Save the access token so that it's used in future calls
componentDidMount() {
**(11:8)** --> return spotifyApi = new Promise((resolve, reject) => {
spotifyApi.clientCredentialsGrant()
.then( => (data) {
console.log('The access token expires in ' + data.body['expires_in']);
console.log('The access token is ' + data.body['access_token']);
});
// using Promises through Promise, Q or when - get Elvis' albums in range [20...29]
spotifyApi.getArtistAlbums('43ZHCT0cAZBISjO8DG9PnE', {limit: 10, offset: 20})
.then(function(data) {
console.log('Album information', data);
}, function(err) {
console.error(err);
});
});
SpotifyWebApi.setPromiseImplementation(Q);
}
}
【问题讨论】:
-
具体是什么问题?
-
我已经更新了代码@jiargolisvt
标签: javascript api reactjs