渲染的SoundCloud部件使用PHP API的私人赛道 [英] Rendering SoundCloud widget for a private track using PHP API

查看:137
本文介绍了渲染的SoundCloud部件使用PHP API的私人赛道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用PHP API来渲染HTML5的SoundCloud部件,但我每次运行命令时,我觉得应该返回小部件的HTML,我只是得到一个异常:

I am trying to render a SoundCloud HTML5 widget using the PHP API, but every time I run the command I think should return the HTML for the widget, I simply get an Exception:

The requested URL responded with HTTP code 302

我意识到这是一个重定向。我不知道就是为什么这是所有我曾经得到,或做什么它真正得到小部件的HTML。

I realise this is a redirect. What I don't know is why that's all I ever get, or what to do about it to actually get the widget HTML.

在API文档说使用PHP,你应该这样做嵌入部件:

The documentation on the API says that to embed the widget using PHP you should do this:

<?php
    require_once 'Services/Soundcloud.php';

    // create a client object with your app credentials
    $client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');

    // get a tracks oembed data
    $track_url = 'http://soundcloud.com/forss/flickermood';
    $embed_info = $client->get('/oembed', array('url' => $track_url));

    // render the html for the player widget
    print $embed_info['html'];

我运行此:

// NB: Fully authorised SoundCloud API instance all working prior to this line
// $this->api refers to an authorised instance of Services_Soundcloud

try {   
        $widget = array_pop(
            json_decode( $this->api->get('oembed', array('url' => $track_url)) )
        );

        print_r($widget);

    } catch (Exception $e)
    {
        print_r($e->getMessage());
    }

,其中track_url其实是我回去用同样的API请求的SoundCloud早期的应用程序的轨道对象时的URL。

where "track_url" is actually the URL I get back when asking SoundCloud for a track object earlier in the app using the same API.

我不肯定实际上这个URL是摆在首位正确的,因为赛道的对象,我回去给在窗体中的URI

I'm not actually sure this URL is correct in the first place, because the track object I get back gives the 'uri' in the form:

[uri] => https://api.soundcloud.com/tracks/62556508

该文档的例子都直 http://soundcloud.com/username/track-permalink URL - 但即使使用已知路径到公共轨道运行API透过oEmbed方法失败的尝试......我仍然得到302异常

The documentation examples all have a straight http://soundcloud.com/username/track-permalink URL - but even using a known path to a public track the attempt to run the API oembed method fails... I still get a 302 Exception.

最后,有提到在'得到'命令allow_redirects设置为false,但没有任何效果,当我加入到用于构建查询到API的参数。我也试图增加额外的卷曲的选择,但同样没有效果。

Finally, there are mentions of setting "allow_redirects" to false in the 'get' command, but this has no effect when I add to the parameters used to build the query to the API. I also tried adding additional cURL options, but that too had no effect.

我绝对支持API访问的SoundCloud内的轨道。

I have definitely enabled API access to the track within SoundCloud.

撞我的头在这墙上的种类。如果任何人有任何指针,我会非常感激听到他们的声音。只是为了清楚起见,我能够通过我所创建的API实例访问所有用户数据,评论等,所以它似乎是工作的罚款。

Kind of banging my head off the wall on this. If anyone has any pointers I'd be very grateful to hear them. Just for clarity's sake, I am able to access all the user data, comments etc. via the API instance I have created, so it appears to be working fine.

推荐答案

感谢您指出了这一点。大家普遍认为你引入歧途的文档中的错误。对于那个很抱歉。我已经更新了文档以修复该错误。下面是更新code样品:<​​/ P>

Thanks for pointing this out. There was a bug in the documentation that lead you astray. Sorry about that. I've updated the docs to fix the bug. Here's the updated code sample:

<?php

require_once 'Services/Soundcloud.php';

// create a client object with your app credentials
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
$client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => 1));

// get a tracks oembed data
$track_url = 'http://soundcloud.com/forss/flickermood';
$embed_info = json_decode($client->get('oembed', array('url' => $track_url)));

// render the html for the player widget
print $embed_info->html;

请注意区别:


  • 您需要如上评论提到CURLOPT_FOLLOWLOCATION设置为1。

  • 您需要将包装从 $客户 - &GT的回报;获得 json_de code

  • 的结果是 stdClass的的对象,而不是一个阵列等等 HTML 酒店使用访问 - 方式&gt; 运营商

  • You need to set CURLOPT_FOLLOWLOCATION to 1 as mentioned in the comments above.
  • You need to wrap the return from $client->get in json_decode
  • The result is an stdClass object, not an Array and so the html property has to be accessed using the -> operator.

希望有所帮助。随意在此案发表评论你仍然有问题,我会修改我的答案。

Hope that helps. Feel free to comment in case you're still having problems and I'll amend my answer.

这篇关于渲染的SoundCloud部件使用PHP API的私人赛道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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