为什么JSON请求我的外部API在我的Spotify应用被取消?

编程入门 行业动态 更新时间:2024-10-28 04:29:24
本文介绍了为什么JSON请求我的外部API在我的Spotify应用被取消?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我建立一个Spotify应用,从一个REST API拉JSON数据,使用URL像

I'm building a Spotify App that pulls JSON data from a REST API, using URLs like

www.mydomain/api/command?option=value

在我的Spotify应用清单,我设置了所需的权限为我的API主持人:

In my Spotify app manifest I have set the required permissions for my API host:

"RequiredPermissions": [ "*.mydomain" ]

我也曾在我的API的响应头配置跨来源资源共享。这是一个真实的例子:

I have also configured Cross-Origin Resource Sharing in the response headers of my API. Here is a real example:

Server: nginx/0.7.65 Date: Thu, 08 Dec 2011 09:07:16 GMT Content-Type: application/json Connection: keep-alive X-Powered-By: Mojolicious (Perl) Set-Cookie: mojolicious=eyJwcmVmcyI6e30sImZpbHRlcnMiOnsicGllciI6eyJzb3VyY2VzIjpbMjBdfSwiZWxlYyI6eyJzb3VyY2VzIjpbMTMsMTddLCJ4dGFncyI6WyJzaG9lZ2F6ZSJdLCJ0YWdzIjpbImVsZWN0cm9uaWMiXX0sInB1bmtkdWIiOnsieHRhZ3MiOlsicmVnZ2FlIl0sInRhZ3MiOlsicHVuayIsImR1YiJdfX0sImV4cGlyZXMiOjEzMjMzMzg4MzZ9--c6d6214525b5d56785eebc99217394a1; Version=1; Path=/; expires=Thu, 08 Dec 2011 10:07:16 GMT Content-Length: 23381 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET Access-Control-Allow-Headers: * 200 OK

在Spotify的,在Chrome网络督察选项卡中,我看到该请求被取消:

In Spotify, in the chrome inspector network tab, I see that the request is being cancelled:

Name: command www.mydomain/api Method: GET Status Text: (canceled) Type: undefined Initiator: jquery-1.js:7180 (Script) Size Content: 13B (0B) Time Latency: 21ms (0.0 days)

如果我在我的桌面上运行我在Chrome的应用程序(外的Spotify)的请求,不取消,一切都很好。

If I run my app in Chrome on my desktop (outside of Spotify) the request is not cancelled and all is good.

我是什么做错了吗?或者,也许这是Spotify的preVIEW释放错误(功能?)?

What am I doing wrong? Or maybe this is a bug (feature?) in Spotify preview release?

推荐答案

一对夫妇的事情可能导致此,我会把他们为了从易到解析到最难的。

A couple of things can cause this, I'll put them in order from easiest to resolve to hardest.

  • 检查是否有正确的 RequiredPermissions 在你的manifest.json
  • 检查您的manifest.json有一个有效的JSON strjcture,你可以像 jsonlint/
  • 确保你没有保存(在文件的起始字节看不见)以BOM字符的文件,这可能会导致明显的解析失败
  • 确保您要查询服务器接受您的起源。在Spotify的所有的应用程序有一个像 SP原点://应用程序的名字,大多数服务器只接受默认的HTTP和HTTPS协议,这样你就可以设置艾策斯 - 控制允许来源到 * ,以确保请求没有被取消。
  • Check that you have the correct RequiredPermissions in your manifest.json
  • Check that your manifest.json has a valid json strjcture, you can do this on websites like jsonlint/
  • Make sure you're not storing the file with a BOM character (invisible byte at the start of the file), this can cause parsing of the manifest to fail
  • Make sure that the server you are querying accepts your origin. All apps in Spotify have an origin like sp://appname, most servers only accept http and https protocols by default, so you can set the Acces-Control-Allow-Origin to * to make sure the request doesn't get cancelled.
  • 最后,我想指出,即使请求有时在检查显示为取消,它仍然有一个正确的反应,所以一定要仔细检查这一点。

    Lastly, I'd like to note that even though a request sometimes shows up in the inspector as cancelled, it'll still have a correct response, so be sure to double-check that as well.

    希望这有助于!

    编辑:有时候,出于某种奇怪的原因,这也有助于建立你的 RequiredPermissions 没有请求的URL 的http:// 或的https:// prepended

    sometimes, for some weird reason, it also helps to set the url you're requesting in RequiredPermissions without the or prepended.

    更多推荐

    为什么JSON请求我的外部API在我的Spotify应用被取消?

    本文发布于:2023-11-17 15:35:22,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1610265.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:JSON   API   Spotify

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!