无需用户交互的自动 Soundcloud PHP Api 身份验证 [英] Automatic Soundcloud PHP Api authentication without user interaction
问题描述
在我的应用程序中,我想将 Soundcloud API 与我自己的 Soundcloud 用户一起使用.Soundcloud API 认证过程涉及用户被重定向到 Soundcloud 主页,登录并授权应用程序,以便该页面可以使用该用户的 API.
In my application i want to use the Soundcloud API with my own Soundcloud user. The Soundcloud API authentication process involves a user being redirected to the Soundcloud homepage, login and authorize the application, so that the page can use the API for this user.
我想自动化整个过程,因为我自己的用户是唯一经过身份验证的用户.这可能吗?
I want to automate the whole process, because my own user is the only user which gets authenticated. Is that possible?
这是我目前的代码:
$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
推荐答案
我正在寻找相同的东西,但根据 soundcloud 的 api(检查在没有 SoundCloud 连接屏幕的情况下进行身份验证 段落):
I'm looking for the same thing, but according to the soundcloud's api (check the Authenticating without the SoundCloud Connect Screen paragraph):
// this example is not supported by the PHP SDK
.. Javascript 也不支持.
..and is not supported by the Javascript neither.
我尝试使用 python 进行身份验证:
I've tryed to auth with python:
# create client object with app and user credentials
client = soundcloud.Client(client_id='YOUR_CLIENT_ID',
client_secret='YOUR_CLIENT_SECRET',
username='YOUR_USERNAME',
password='YOUR_PASSWORD')
..然后上传python方法:
..then the uploading python method:
# upload audio file
track = client.post('/tracks', track={
'title': 'This is my sound',
'asset_data': open('file.mp3', 'rb')
})
它工作得很好.
所以,现在,您有两种方法:
So, for now, you have 2 ways:
- 使用另一种语言,Python 或 Ruby(仅有的 2 个实际支持此功能的 sdk)或使用小型 Python/ruby 脚本作为满足此特定需求的桥梁;
- 将此功能添加到 PHP SDK(我正在尝试快速完成,如果成功,我会分享;)
这篇关于无需用户交互的自动 Soundcloud PHP Api 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!