简体   繁体   English

Oauth Spotify API与PHP

[英]Oauth Spotify API with PHP

I have been working with the Spotify API. 我一直在使用Spotify API。 I want to perform some actions on playlists, these require a user to login. 我要对播放列表执行一些操作,这些操作需要用户登录。 I want to execute the following url so as I can get an authorization bearer: 我想执行以下网址,以便获得授权承载:

https://accounts.spotify.com/authorize/?client_id=CLIENT_ID&response_type=token&redirect_uri=http%3A%2F%2Flocalhost%3A8888%2Fcallback&scope=user-read-private%20playlist-modify-public&state=34fFs29kd09 https://accounts.spotify.com/authorize/?client_id=CLIENT_ID&response_type=token&redirect_uri=http%3A%2F%2Flocalhost%3A8888%2Fcallback&scope=user-read-private%20playlist-modify-public&state=34fFs29kd09

When I execute this in a browser URL field, it works fine and will return an authorization token. 当我在浏览器URL字段中执行此操作时,它可以正常工作,并将返回授权令牌。 I fi try to execute this from an index.php file however I run into problems. 我尝试从index.php文件执行此操作,但是遇到了问题。

<?php 
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
$output = curl_exec($curl);
curl_close($curl);
?>

When i run the file, the spotify login page will appear. 当我运行文件时,将显示spotify登录页面。 However, after I enter my login details and hit enter nothing happens. 但是,在我输入我的登录详细信息并按回车之后,什么也没有发生。

The console in the browser reports the following error: 浏览器中的控制台报告以下错误:

POST http://localhost:8888/api/login 404 (Not Found) TypeError: Cannot create property 'error' on string ' POST http:// localhost:8888 / api / login 404(未找到)TypeError:无法在字符串'上创建属性'error'

<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /api/login was not found on this server.</p>
</body></html>

I have added a .htaccess to the folder as well as change the Directory AllowOverride to All in the httpd.conf file in my mamps server. 我已将.htaccess添加到该文件夹​​,并将我的Mamps服务器中httpd.conf文件中的目录AllowOverride更改为All。 There are multiple AllowOverrides and I am not 100% sure which one to change. 有多个AllowOverrides,但我不确定100%更改哪一个。

If it isn't obvious by now, I am copmletly lost when it comes to this so any help would be gratefully appreciated. 如果到现在为止还不很清楚,我会迷失在这个问题上,因此不胜感激。

Are your sure that page on localhost exists on that port? 您确定本地主机上的页面在该端口上存在吗? Is that page white listed on your dev-account on spotify? 该页面是否在Spotify的开发人员帐户上列出为白色?

You can also try this package from jwilsson, this way you don't have to fight whith the whole oauth process. 您也可以从jwilsson尝试使用软件包,这样就不必与整个oauth流程进行斗争。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM