gpt4 book ai didi

php - 无需用户交互的自动 Soundcloud PHP Api 身份验证

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:36:29 26 4
gpt4 key购买 nike

在我的应用程序中,我想将 Soundcloud API 与我自己的 Soundcloud 用户一起使用。 Soundcloud API 身份验证过程涉及将用户重定向到 Soundcloud 主页,登录并授权应用程序,以便该页面可以使用该用户的 API。

我想自动化整个过程,因为我自己的用户是唯一获得身份验证的用户。这可能吗?

到目前为止,这是我的代码:

    $soundcloud = new \Services_Soundcloud(
'**',
'**',
'http://**'
);

$authorizeUrl = $soundcloud->getAuthorizeUrl();

$accessToken = $soundcloud->accessToken();

try {
$me = json_decode($soundcloud->get('me'), true);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}

但是行 $accessToken = $soundcloud->accessToken(); 抛出异常:

The requested URL responded with HTTP code 401.
500 Internal Server Error - Services_Soundcloud_Invalid_Http_Response_Code_Exception

最佳答案

Hi All,

Here I am going to share my experience with Soundcloud API (PHP)

查看我的问题:Link

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());
}

I had check the $_GET['code'] value. But strange there is nothing in $_GET['code'] this is blank. The Soundcloud was returning "The requested URL responded with HTTP code 0" error. That time I was testing Soundcloud on WAMP Localhost.

Allot of Goggling I found a solution to fix "The requested URL responded with HTTP code 0" issue. I had download 'cacert.pem' file and put inside our demo project folder (inside Services/Soundcloud/). Then after I added some code in 'class 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);

Saved 'class Services_Soundcloud' file and moved on live server. After move my project from WAMP to Live server I start to check it again. When I open my index.php it's ask me to login

enter image description here

I use my Facebook account to login.

enter image description here

after login it was asking to connect with Soundcloud

enter image description here

after connect everything working smooth, I got my info with

$me = json_decode($soundcloud->get('me'));

but a new problem start to occurring which was that my access token being expire again and again. Then I use session :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 干杯!!!! :)

关于php - 无需用户交互的自动 Soundcloud PHP Api 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8708791/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com