ReactJS componentDidMount、Fetch Spotify API、Promise

user7904085

ReactJS、Spotify API、Promiseの使い方を学んでいます。Spotifyでミュージシャンのトップアルバムを取得して、トラックの30秒を再生しようとしています。

私はspotify-web-api-nodeと呼ばれるSpotifyパッケージを使用しています。ReactまたはJSについて基本的なことを理解していないと思います。Syntax error: Unexpected token, expected ( (11:8)

'react'から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);
  }
}
オースティングレコ

constそのようなクラス内に定義を含めることはできません

外に移動するか、const:を削除する必要があります

// 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
});

export default class SpotifyComponent extends React.Component {

または

export default class SpotifyComponent extends React.Component {
  // Create the api object with the credentials
  spotifyApi = new SpotifyWebApi({
    clientId : process.env.REACT_APP_SPOTIFY_CLIENT_ID,
    clientSecret : process.env.REACT_APP_SPOTIFY_CLIENT_SECRET
  });

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Spotify API returns empty body

分類Dev

向 ReactJS 添加 JS 函數 - Spotify Web Playback SDK

分類Dev

Spotipy - Spotify API for Python invalid recommendation request

分類Dev

How to call Spotify API with Ajax / Jquery?

分類Dev

Axios post spotify api request return 400

分類Dev

cURL request Spotify API Unexpected status: 415

分類Dev

ReactJS server side rendering and componentDidMount method

分類Dev

Spotify API Web:Node.jsなしのOAuth

分類Dev

See what friends and followed people are playing with Spotify API

分類Dev

Spotify API 400 Error Only Valid Bearer Authentication Supported

分類Dev

Correct python syntax to search by artist in Spotify's Search API?

分類Dev

Why are dots in track name confusing searches via Spotify Web API?

分類Dev

SpotifyメタデータAPI + libspotify

分類Dev

Spotify web api, get follow playlist's tracks

分類Dev

PHPの致命的なエラー/ Spotify Web API

分類Dev

ReactJSのcomponentDidMount内の複数のAPI呼び出し内の複数のセット状態

分類Dev

ReactjsのcomponentDidMountとgetInitialStateの違い

分類Dev

ReactJS componentDidMount +レンダリング

分類Dev

ReactJs Promise + Ajaxの戻り値

分類Dev

Reactjs ajax Uncaught(in promise)ReferenceError:$ is undefined

分類Dev

Spotify Webhooks?

分類Dev

How to test react components when fetch in componentDidMount?

分類Dev

fetch-API ReadableStreamはpromise.then(...)で機能しますか?

分類Dev

Spotify Web APIを使用して、自分のWebサイト内で完全なSpotifyトラックを再生します

分類Dev

空(SpotifyはAPIを)返す特定の検索結果

分類Dev

Docker(Spotify)API-Dockerに接続できません

分類Dev

CORS 정책에 의해 차단 된 Spotify API-localhost

分類Dev

Spotify Open API の使用時に CORS エラーが発生する

分類Dev

O token de acesso recuperado da API Spotify não está funcionando

Related 関連記事

  1. 1

    Spotify API returns empty body

  2. 2

    向 ReactJS 添加 JS 函數 - Spotify Web Playback SDK

  3. 3

    Spotipy - Spotify API for Python invalid recommendation request

  4. 4

    How to call Spotify API with Ajax / Jquery?

  5. 5

    Axios post spotify api request return 400

  6. 6

    cURL request Spotify API Unexpected status: 415

  7. 7

    ReactJS server side rendering and componentDidMount method

  8. 8

    Spotify API Web:Node.jsなしのOAuth

  9. 9

    See what friends and followed people are playing with Spotify API

  10. 10

    Spotify API 400 Error Only Valid Bearer Authentication Supported

  11. 11

    Correct python syntax to search by artist in Spotify's Search API?

  12. 12

    Why are dots in track name confusing searches via Spotify Web API?

  13. 13

    SpotifyメタデータAPI + libspotify

  14. 14

    Spotify web api, get follow playlist's tracks

  15. 15

    PHPの致命的なエラー/ Spotify Web API

  16. 16

    ReactJSのcomponentDidMount内の複数のAPI呼び出し内の複数のセット状態

  17. 17

    ReactjsのcomponentDidMountとgetInitialStateの違い

  18. 18

    ReactJS componentDidMount +レンダリング

  19. 19

    ReactJs Promise + Ajaxの戻り値

  20. 20

    Reactjs ajax Uncaught(in promise)ReferenceError:$ is undefined

  21. 21

    Spotify Webhooks?

  22. 22

    How to test react components when fetch in componentDidMount?

  23. 23

    fetch-API ReadableStreamはpromise.then(...)で機能しますか?

  24. 24

    Spotify Web APIを使用して、自分のWebサイト内で完全なSpotifyトラックを再生します

  25. 25

    空(SpotifyはAPIを)返す特定の検索結果

  26. 26

    Docker(Spotify)API-Dockerに接続できません

  27. 27

    CORS 정책에 의해 차단 된 Spotify API-localhost

  28. 28

    Spotify Open API の使用時に CORS エラーが発生する

  29. 29

    O token de acesso recuperado da API Spotify não está funcionando

ホットタグ

アーカイブ