【问题标题】:Cakephp: get youTube playlist as json and send data to viewCakephp:以 json 格式获取 YouTube 播放列表并发送数据以查看
【发布时间】:2012-11-16 02:48:33
【问题描述】:

我想从我的 youtube 播放列表中调用数据。据我所知,返回的是json。 将数据调用到控制器中的最佳方式是什么?

我试过了

$url = 'http://gdata.youtube.com/feeds/api/playlists/myid?&v=2&alt=json&callback=?';
$result = Set::reverse(json_decode(file_get_contents($url)));

但它返回给我这个错误: 无法打开流:HTTP 请求失败! HTTP/1.0 400 错误请求

如果我用 jquery 试试

$.getJSON('http://gdata.youtube.com/feeds/api/playlists/myid?&v=2&alt=json&callback=?',function(data) {

我得到一个数据结果并使用它。

以“蛋糕”方式检索json数据的正确方法是什么?

【问题讨论】:

    标签: xml json cakephp youtube


    【解决方案1】:

    你用的是什么版本的 cakephp?

    这适用于 2.x,应该可以工作

    App::uses('HttpSocket', 'Network/Http');
    $this->Http = new HttpSocket();
    $_result = $this->Http->get('http://gdata.youtube.com/feeds/api/playlists/myid?&v=2');
    pr(Set::reverse(json_decode($_result)));
    

    【讨论】:

      【解决方案2】:

      通过发帖我找到了解决方案:

      $url = 'http://gdata.youtube.com/feeds/api/playlists/myid?&v=2';
          $result = Set::reverse(Xml::build($url));
          debug($result);
      

      不需要 json :-) 只需调用 xml 反馈并将其推送到一个数组中,然后做你想做的 :-)

      【讨论】:

        猜你喜欢
        • 2015-08-25
        • 1970-01-01
        • 2017-05-18
        • 2017-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-31
        相关资源
        最近更新 更多