Accessing Spotify Metadata API from within a Spotify app?

无人久伴 提交于 2019-12-30 11:12:08

问题


I want to run Spotify searches from within a Spotify app (to find tracks for an artist, for which I do not have a Spotify URI, only the name).

I have not found functionality in the App API to run searches. An alternative is to talk to ws.spotify.com to get to Spotify's search, but these web services do not support jsonp which is required for their use in a Spotify app.

What are my options?


回答1:


This is not the finest way to solve your problem. There is a direct API for searching within your app. See Juan's solution.

But you could also talk to ws.spotify.com directly when you add the domain to your app's manifest.json.

"RequiredPermissions": ["http://ws.spotify.com" ]

e.g. http://ws.spotify.com/search/1/track.json?q=kaizers+orchestra, see their Developer Site. The response contains the header "Access-Control-Allow-Origin: *", so you should be able to query from within your app.




回答2:


You can use sp.core.search

sp.core.search("query",
    {onSuccess: function(result) {
        // parse result
        }
    }
);

sp.core.getMetadata if you have the uri

    sp.core.getMetadata("uri", {
        onSuccess: function(data){
            console.debug(data);
        },
        onFailure: function(){
                //...
        },
    });


来源:https://stackoverflow.com/questions/8408581/accessing-spotify-metadata-api-from-within-a-spotify-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!