【问题标题】:Youtube API v3 - Retrieving channel nameYoutube API v3 - 检索频道名称
【发布时间】:2016-03-12 12:39:09
【问题描述】:

我在获取频道名称(标题)方面需要帮助。我想用json_decode 来做,但我不知道怎么做。请帮助我 :) 谢谢 :)

https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername=$youtubechannel&key=YOUR_KEY&getJSON

$url="https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername=$youtubechannel&key=YOUR_KEY&getJSON";
$json = file_get_contents($url);
$json_result = json_decode($json, TRUE);
$raw_channel_name =  $json_result->results[0];
$channel_name = $raw_channel_name->title;
echo $channel_name;

【问题讨论】:

    标签: php json youtube


    【解决方案1】:

    我更喜欢使用 CURL 而不是“file_get_contents”,它更灵活。

    关于 json_decode,如果你想处理一个对象,那么去掉第二个参数。 “YES”参数将结果强制为 ARRAY 而不是对象。

    json_decode($json)
    

    如果你使用第二个参数,那么:

    $result = json_decode($json,YES) 
    
    var_dump($result);
    

    你会看到一个数组。

    【讨论】:

      猜你喜欢
      • 2015-07-22
      • 2016-10-11
      • 2014-10-13
      • 1970-01-01
      • 2015-01-02
      • 2023-04-03
      • 2016-08-30
      • 1970-01-01
      • 2016-01-22
      相关资源
      最近更新 更多