且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用于Spotify的无效重定向URI

更新时间:2023-12-04 13:14:10

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

There are several ways you can do it. I recommend you to have a look at the possan/webapi-player-example, which is built using AngularJS and uses a PostMessage to communicate between the redirect URI (callback.html) and the Angular app (app.js).

如果没有PostMessages选项,则可以尝试以下操作:

If PostMessages is not an option, you can try this:

  1. 启动循环以检查localStorage
  2. 上的特定键
  3. 在弹出窗口中打开登录页面.
  4. 在回调页面上,写入localStorage从Spotify获得的数据(即access_tokenrefresh_tokenexpires_in).
  5. 几秒钟后关闭弹出窗口
  6. 该循环应该已经意识到要在localStorage中写入新值.
  1. Start a loop to check a certain key on localStorage
  2. Open the login page in a popup.
  3. From the callback page, write in localStorage the data you get back from Spotify (i.e. access_token, refresh_token, expires_in).
  4. Close the popup after a couple of seconds
  5. The loop should have realised about the new value being written in localStorage.

先前的流程虽然稍微复杂一点,但在诸如iOS设备之类的环境中效果很好,有时无法正确地在回调页面和主"页面之间进行通信.

The previous flow, although a bit more complex, works well in environments such as iOS devices where it is sometimes impossible to communicate between the callback page and the "main" page properly.