Ich lerne, wie ReactJS, Spotify API und Promise verwendet. Ich versuche, Musiker Top-Alben auf Spotify zu holen und 30 Sekunden des Tracks zu spielen.ReactJS componentDidMount, Fetch Spotify API und Promise
Ich verwende ein Spotify-Paket namens spotify-web-api-node Ich glaube, ich verstehe etwas grundlegend über React oder JS. Syntax error: Unexpected token, expected ((11:8)
importieren Reagieren von 'reagieren';
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);
}
}
Was ist das spezifische Problem? – jmargolisvt
Ich habe update den Code @jiargolisvt –