使用 Spotify 授权 API
Authorizing with Spotify API
我已经通过 Spotify 在我的项目上设置了授权,它可以在本地和我的 Heroku 暂存环境中运行,但不能在我的 Heroku 生产环境中运行。它要么超时,要么停留在空白页上。能够通过 Facebook 将其登录到 Spotify 一次,但在提交时超时。不知道是什么原因造成的,想知道是不是因为应用程序中添加了自定义域。
onSuccess = (response, mutation) => {
this.setState({error: false, loading: true})
mutation({
variables: { accessToken: response.access_token}
})
.then((res) => {
this.setState({loading: false})
this.props.history.push(`/`)
window.location.reload();
})
.catch((error) => {
this.setState({loading: false})
this.setState({error: true, errorMsg: "Something went wrong, please try again"})
})
}
onFailure = (response) => {
this.setState({click: false, error: true, errorMsg: "Something went wrong, please try again"})
}
<SpotifyLogin
clientId={process.env.REACT_APP_SPOTIFY_ID}
onClick={() => this.setState({click: true})}
redirectUri={process.env.REACT_APP_SPOTIFY_URL || "http://localhost:3000/"}
onSuccess={(data) => this.onSuccess(data, mutation)}
onFailure={this.onFailure}
scope="user-read-private user-top-read user-read-email user-read-playback-state"
className="onboarding__spotify-cta"
/>
如果问题不在您的开发环境中,而是在您的生产环境中,那是因为您的重定向 uri 有问题,请检查您的 process.env.REACT_APP_SPOTIFY_URL
是否正确
我已经通过 Spotify 在我的项目上设置了授权,它可以在本地和我的 Heroku 暂存环境中运行,但不能在我的 Heroku 生产环境中运行。它要么超时,要么停留在空白页上。能够通过 Facebook 将其登录到 Spotify 一次,但在提交时超时。不知道是什么原因造成的,想知道是不是因为应用程序中添加了自定义域。
onSuccess = (response, mutation) => {
this.setState({error: false, loading: true})
mutation({
variables: { accessToken: response.access_token}
})
.then((res) => {
this.setState({loading: false})
this.props.history.push(`/`)
window.location.reload();
})
.catch((error) => {
this.setState({loading: false})
this.setState({error: true, errorMsg: "Something went wrong, please try again"})
})
}
onFailure = (response) => {
this.setState({click: false, error: true, errorMsg: "Something went wrong, please try again"})
}
<SpotifyLogin
clientId={process.env.REACT_APP_SPOTIFY_ID}
onClick={() => this.setState({click: true})}
redirectUri={process.env.REACT_APP_SPOTIFY_URL || "http://localhost:3000/"}
onSuccess={(data) => this.onSuccess(data, mutation)}
onFailure={this.onFailure}
scope="user-read-private user-top-read user-read-email user-read-playback-state"
className="onboarding__spotify-cta"
/>
如果问题不在您的开发环境中,而是在您的生产环境中,那是因为您的重定向 uri 有问题,请检查您的 process.env.REACT_APP_SPOTIFY_URL
是否正确