【问题标题】:Authorizing with Spotify API使用 Spotify API 进行授权
【发布时间】:2020-10-06 20:07:13
【问题描述】:

我已经通过 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"
    />

【问题讨论】:

  • 如果您需要帮助,请提供一些代码。
  • 刚刚添加!不确定在这种情况下会有所帮助。 @JonathanDelean

标签: api authentication heroku oauth spotify


【解决方案1】:

如果问题不在您的开发环境中,而是在您的产品中,这是因为您的重定向 uri 有问题,请检查您的 process.env.REACT_APP_SPOTIFY_URL 是否正确

【讨论】:

  • 我以为我已经涵盖了但我缺少一个角色,感谢帮助!
猜你喜欢
  • 2014-08-13
  • 1970-01-01
  • 2018-05-21
  • 1970-01-01
  • 2019-07-18
  • 2021-07-04
  • 2017-12-29
  • 2018-08-12
  • 2017-12-23
相关资源
最近更新 更多