大家好,
在这里我将分享我使用 Soundcloud API (PHP) 的经验
请参阅我的问题:链接
Recently I started to work with Sound cloud API (PHP) and I decided to use PHP API by
https://github.com/mptre/php-soundcloud.
But When I was trying to get access token from Sound cloud server by this code:
// Get access token
try {
$accessToken = $soundcloud->accessToken($_GET['code']);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
我检查了 $_GET['code'] 值。但奇怪的是 $_GET['code'] 中没有任何内容,这是空白的。Soundcloud 正在返回“请求的 URL 以 HTTP 代码 0 响应”错误。那个时候我在 WAMP 本地主机上测试 Soundcloud。
Goggling 的分配我找到了解决“请求的 URL 响应 HTTP 代码 0”问题的解决方案。我已经下载了“cacert.pem”文件并将其放入我们的演示项目文件夹中(在 Services/Soundcloud/ 中)。然后在我在“类 Services_Soundcloud”中添加了一些代码之后
function protected function _request($url, $curlOptions = array()).
// My code in side function
$curlPath = realpath(getcwd().'\Services\cacert.pem');
$curlSSLSertificate = str_replace("\\", DIRECTORY_SEPARATOR, $curlPath);
curl_setopt($ch, CURLOPT_CAINFO, $curlSSLSertificate);
保存“类 Services_Soundcloud”文件并移至实时服务器。将我的项目从 WAMP 移动到 Live 服务器后,我开始再次检查它。当我打开我的 index.php 时,它要求我登录

I use my Facebook account to login.

after login it was asking to connect with Soundcloud

连接一切顺利后,我得到了我的信息
$me = json_decode($soundcloud->get('me'));
但是开始出现一个新问题,那就是我的访问令牌一次又一次地过期。然后我使用会话:D
// code for access token
$code = $_GET['code'];
// Get access token
try {
if(!isset($_SESSION['token'])){
$accessToken = $soundcloud->accessToken($code);
$_SESSION['token'] = $accessToken['access_token'];
}else{
$soundcloud->setAccessToken($_SESSION['token']);
}
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
现在一切都很棒。我可以获取我的所有详细信息,从 SC 服务器跟踪所有内容
希望它可以帮助您与 Soundcloud API 干杯!!!!:)