ReactJS, Spotify API 및 Promise 사용법을 배우고 있습니다. Spotify에서 뮤지션의 톱 앨범을 가져 와서 30 초 동안 재생하려고합니다.ReactJS componentDidMount, Spotify API 및 약속 가져 오기
나는 Spotify 패키지 spotify-web-api-node을 사용하고 있습니다. 저는 React 또는 JS에 대한 근본적인 것을 이해하지 못한다고 생각합니다. Syntax error: Unexpected token, expected ((11:8)
수입 반응 'react';
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);
}
}
특정 문제가 무엇입니까? – jmargolisvt
나는 코드를 갱신했다 @jiargolisvt –