【问题标题】:Invalid redirect URI for spotifyspotify 的重定向 URI 无效
【发布时间】:2014-10-03 10:37:50
【问题描述】:

我正在尝试让 Spotify API 与 AngularJS 一起工作。我在授权阶段收到无效的重定向 URI 错误 (https://developer.spotify.com/web-api/authorization-guide/)。

我在白名单中添加了redirect_uri,当我有一个URI时它可以工作

http://localhost:3000 

但是当我有一个带有哈希的 URI 时它不起作用

http://localhost:3000/#/main

我想使用后一个 URI 的原因是因为使用前者我得到一个 URI,但我无法通过 angular 获取参数

http://localhost:3000/<parameters returned from spotify>/#/main) 

而我希望 URI 是这样的:

http://localhost:3000/#/main/<parameters returned from spotify>

任何帮助将不胜感激,谢谢。

【问题讨论】:

  • 对 Angular 不是很了解,但你不能在后端创建一个特定的端点来接收授权码,例如http://:3000/handle-auth/,重定向到 /#/main?

标签: angularjs spotify


【解决方案1】:

有几种方法可以做到这一点。我建议您查看possan/webapi-player-example,它是使用 AngularJS 构建的,并使用 PostMessage 在重定向 URI (callback.html) 和 Angular 应用程序 (app.js) 之间进行通信。

如果 PostMessages 不是一个选项,你可以试试这个:

  1. 开始循环检查localStorage 上的某个键
  2. 在弹出窗口中打开登录页面。
  3. 在回调页面中,将您从 Spotify 返回的数据写入localStorage(即access_tokenrefresh_tokenexpires_in)。
  4. 几秒钟后关闭弹出窗口
  5. 循环应该已经意识到要写入 localStorage 的新值。

前面的流程虽然有点复杂,但在 iOS 设备等有时无法在回调页面和“主”页面之间正常通信的环境中运行良好。

【讨论】:

  • 我已经尝试过了,我已经设法获得了令牌,谢谢。
猜你喜欢
  • 2021-03-12
  • 2020-07-16
  • 2016-01-02
  • 2017-05-31
  • 2015-02-05
  • 2020-02-17
  • 2015-03-12
  • 1970-01-01
  • 2022-08-08
相关资源
最近更新 更多