无需用户交互的SoundCloud自动PHP API认证 [英] Automatic Soundcloud PHP Api authentication without user interaction

查看:274
本文介绍了无需用户交互的SoundCloud自动PHP API认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序要使用的SoundCloud API用我自己的SoundCloud的用户。该API的SoundCloud认证过程涉及用户被重定向到的SoundCloud主页,登录和授权应用,使该页面可以使用API​​此用户。

我要自动运行的全过程,因为我自己的用户是通过验证的用户。这可能吗?

下面是我的code迄今:

  $ =的SoundCloud新\\ Services_Soundcloud(
        '**',
        '**',
        的http:// **
    );    $ authorizeUrl = $ soundcloud-> getAuthorizeUrl();    $的accessToken = $ soundcloud->的accessToken();    尝试{
        $ =我json_de code($ soundcloud->获得(我),TRUE);
    }赶上(Services_Soundcloud_Invalid_Http_Response_ code_Exception $ E){
        出口($ E->的getMessage());
    }

但线 $的accessToken = $ soundcloud->的accessToken(); 抛出异常:

 请求的URL与HTTP $ C $回应Ç401。
500内部服务器错误 - Services_Soundcloud_Invalid_Http_Response_ code_Exception


解决方案

我在寻找同样的事情,但根据的的SoundCloud的API (检查的不进行身份验证的SoundCloud的连接屏幕的段落):

  //这个例子不是由PHP SDK支持

..并没有被Javascript没有。

支持

我trye​​d与蟒蛇权威性:

 #创建应用程序和用户证书的客户端对象
客户端= soundcloud.Client(CLIENT_ID ='YOUR_CLIENT_ID',
                           client_secret ='YOUR_CLIENT_SECRET',
                           用户名='YOUR_USERNAME',
                           密码='YOUR_PASSWORD')

..然后上传蟒蛇方式:

 #上传音频文件
轨道= client.post('/曲目',跟踪= {
    标题:这是我的声音,
    asset_data:开放('file.mp3,RB)
})

和它工作得很好。

所以,现在,你有2种方式:


  1. 使用另一种语言,Python或Ruby(只有2 SDK实际上支持此功能),或使用一个小的Python / Ruby脚本作为此特别需要的桥梁;

  2. 这funcionaliy添加到PHP SDK(我试图quick'n'dirty做到这一点,如果我得到的成功,我将分享;)

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?

Here is my code so far:

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

But the line $accessToken = $soundcloud->accessToken(); throws an exception:

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

解决方案

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

..and is not supported by the Javascript neither.

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')

..then the uploading python method:

# upload audio file
track = client.post('/tracks', track={
    'title': 'This is my sound',
    'asset_data': open('file.mp3', 'rb')
})

and it works just fine.

So, for now, you have 2 ways:

  1. Use another language, Python or Ruby (the only 2 sdk that actually support this feature) or use a small python/ruby script as a bridge for this particular need;
  2. Add this funcionaliy to the PHP SDK (i'm trying to do it quick'n'dirty, if i get success, i'll share ;)

这篇关于无需用户交互的SoundCloud自动PHP API认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆