简体   繁体   English

无法检索 Spotify api 令牌

[英]Can't retrieve spotify api token

I am using the react-spotify-login package and when trying to authorize the application I can't retrieve the access token.我正在使用 react-spotify-login 包,但在尝试授权应用程序时,我无法检索访问令牌。 My routing works and sending the request works.我的路由有效并且发送请求有效。 I just can't retrieve the token.我只是无法检索令牌。 I've just started learning react so I'm hoping it isn't something I'm easily overlooking.我刚刚开始学习反应,所以我希望它不是我很容易忽视的东西。

import React, { Component } from 'react';
import SpotifyLogin from 'react-spotify-login';
import { clientId, redirectUri } from '../../Settings';
import { Redirect } from 'react-router-dom';




export class Login extends Component {
    render() {
        const onSuccess = ({ response }) => {
            //const { access_token: token } = response;
            console.log("[onSuccess]" + response);
            return <Redirect to='/home' />
        };

        const onFailure = response => console.error("[onFailure]" + response);

        return (
            <div>
                <SpotifyLogin
                    clientId={clientId}
                    redirectUri={redirectUri}
                    onSuccess={onSuccess}
                    onFailure={onFailure}
                />
            </div>
        );
    }
}
export default Login;

In your approach you are trying to destructure the response data/object and pull field 'response' which does not exist ie undefined在您的方法中,您试图解构响应数据/对象并拉取不存在的字段“响应”,即未定义

Change改变

const onSuccess = ({ response }) => {

to

const onSuccess = (response) => {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM