【问题标题】:Display stdClass Object Result from Youtube API V3显示来自 Youtube API V3 的 stdClass 对象结果
【发布时间】:2015-09-09 07:40:31
【问题描述】:
Array ( [results] => Array ( [0] => stdClass Object ( [kind] => youtube#playlistItem [etag] => "sGDdEsjSJ_SnACpEvVQ6MtTzkrI/Hld9sAU5IF-CaWnmAvvbwdVOmW8" [id] => PLGPyqY_HX5wk4cLJaX50d7Ncr5vEvh2xET5o9rHCUuZo [snippet] => stdClass Object ( [publishedAt] => 2015-09-05T05:58:01.000Z [channelId] => UCufw5B9GPI2ZKXcq0r3GPvg [title] => Intellisense Institute of Technology - Students Quick Talk [description] => Intellisense Institute of Technology - Students Quick Talk [thumbnails] => stdClass Object ( [default] => stdClass Object ( [url] => https://i.ytimg.com/vi/Q9oYREOUAEo/default.jpg [width] => 120 [height] => 90 ) [medium] => stdClass Object ( [url] => https://i.ytimg.com/vi/Q9oYREOUAEo/mqdefault.jpg [width] => 320 [height] => 180 ) [high] => stdClass Object ( [url] => https://i.ytimg.com/vi/Q9oYREOUAEo/hqdefault.jpg [width] => 480 [height] => 360 ) ) [channelTitle] => Bobby Gerez [playlistId] => PL9Rdj0W_2qbNczyMChLB4GNfDrrmNVYd6 [position] => 0 [resourceId] => stdClass Object ( [kind] => youtube#video [videoId] => Q9oYREOUAEo ) ) [contentDetails] => stdClass Object ( [videoId] => Q9oYREOUAEo ) [status] => stdClass Object ( [privacyStatus] => public ) ) [1] => stdClass Object ( [kind] => youtube#playlistItem [etag] => "sGDdEsjSJ_SnACpEvVQ6MtTzkrI/O4GbKescshBt3X2Qd32HOEM168I" [id] => PLGPyqY_HX5wk4cLJaX50d7F9HqUVBzz-yP78l5pCY5hk [snippet] => stdClass Object ( [publishedAt] => 2015-09-05T05:58:01.000Z [channelId] => UCufw5B9GPI2ZKXcq0r3GPvg [title] => Intellisense Institute of Technology - Students Quick Talk [description] => Intellisense Institute of Technology - Students Quick Talk [thumbnails] => stdClass Object ( [default] => stdClass Object ( [url] => https://i.ytimg.com/vi/qqNt3uUC_nU/default.jpg [width] => 120 [height] => 90 ) [medium] => stdClass Object ( [url] => https://i.ytimg.com/vi/qqNt3uUC_nU/mqdefault.jpg [width] => 320 [height] => 180 ) [high] => stdClass Object ( [url] => https://i.ytimg.com/vi/qqNt3uUC_nU/hqdefault.jpg [width] => 480 [height] => 360 ) ) [channelTitle] => Bobby Gerez [playlistId] => PL9Rdj0W_2qbNczyMChLB4GNfDrrmNVYd6 [position] => 1 [resourceId] => stdClass Object ( [kind] => youtube#video [videoId] => qqNt3uUC_nU ) ) [contentDetails] => stdClass Object ( [videoId] => qqNt3uUC_nU ) [status] => stdClass Object ( [privacyStatus] => public ) ) [2] => stdClass Object ( [kind] => youtube#playlistItem [etag] => "sGDdEsjSJ_SnACpEvVQ6MtTzkrI/KwLYVUcNfNgsEdZWk8Ub4oycqVs" [id] => PLGPyqY_HX5wk4cLJaX50d7K2ilGj1zLQkk6B69-lsmbY [snippet] => stdClass Object ( [publishedAt] => 2015-09-05T05:58:01.000Z [channelId] => UCufw5B9GPI2ZKXcq0r3GPvg [title] => Intellisense Institute of Technology - Students Quick Talk [description] => Intellisense Institute of Technology - Students Quick Talk [thumbnails] => stdClass Object ( [default] => stdClass Object ( [url] => https://i.ytimg.com/vi/Y68mvebLIz8/default.jpg [width] => 120 [height] => 90 ) [medium] => stdClass Object ( [url] => https://i.ytimg.com/vi/Y68mvebLIz8/mqdefault.jpg [width] => 320 [height] => 180 ) [high] => stdClass Object ( [url] => https://i.ytimg.com/vi/Y68mvebLIz8/hqdefault.jpg [width] => 480 [height] => 360 ) ) [channelTitle] => Bobby Gerez [playlistId] => PL9Rdj0W_2qbNczyMChLB4GNfDrrmNVYd6 [position] => 2 [resourceId] => stdClass Object ( [kind] => youtube#video [videoId] => Y68mvebLIz8 ) ) [contentDetails] => stdClass Object ( [videoId] => Y68mvebLIz8 ) [status] => stdClass Object ( [privacyStatus] => public ) ) [3] => stdClass Object ( [kind] => youtube#playlistItem [etag] => "sGDdEsjSJ_SnACpEvVQ6MtTzkrI/oxHss_K55L38RyWvBnYGApuo70Q" [id] => PLGPyqY_HX5wk4cLJaX50d7JV7qr-HCuLFHnpjKfMAJW0 [snippet] => stdClass Object ( [publishedAt] => 2015-09-05T05:58:01.000Z [channelId] => UCufw5B9GPI2ZKXcq0r3GPvg [title] => Intellisense Institute of Technology - Students Quick Talk [description] => Intellisense Institute of Technology - Students Quick Talk [thumbnails] => stdClass Object ( [default] => stdClass Object ( [url] => https://i.ytimg.com/vi/QDJWlFidvOA/default.jpg [width] => 120 [height] => 90 ) [medium] => stdClass Object ( [url] => https://i.ytimg.com/vi/QDJWlFidvOA/mqdefault.jpg [width] => 320 [height] => 180 ) [high] => stdClass Object ( [url] => https://i.ytimg.com/vi/QDJWlFidvOA/hqdefault.jpg [width] => 480 [height] => 360 ) [standard] => stdClass Object ( [url] => https://i.ytimg.com/vi/QDJWlFidvOA/sddefault.jpg [width] => 640 [height] => 480 ) [maxres] => stdClass Object ( [url] => https://i.ytimg.com/vi/QDJWlFidvOA/maxresdefault.jpg [width] => 1280 [height] => 720 ) ) [channelTitle] => Bobby Gerez [playlistId] => PL9Rdj0W_2qbNczyMChLB4GNfDrrmNVYd6 [position] => 3 [resourceId] => stdClass Object ( [kind] => youtube#video [videoId] => QDJWlFidvOA ) ) [contentDetails] => stdClass Object ( [videoId] => QDJWlFidvOA ) [status] => stdClass Object ( [privacyStatus] => public ) ) ) )

您可以参考这个网站http://iitcebu.net/video_gallery。问题是如何获取 videoId 视频。我今天一直在做这个,我无法让它工作。到目前为止,这是我的代码

foreach ($playlistItems['results'] as $value){
        foreach($value as $val){
            if(is_object($val)){
                foreach($val as $v){

                    print_r($v);
                    echo "<hr />";
                }
            }
        }        
    }

我什至无法访问 videoId。

【问题讨论】:

    标签: stdclass youtube-data-api


    【解决方案1】:

    我已成功管理 Youtube API v3 中的 stdClass 对象。这是我输出videoId的代码。希望对您有所帮助。

    $count = count($playlistItems['results']);
    
        for($i = 0; $i <= $count-1; $i++){
    
            $items = $playlistItems['results'][$i]->snippet->resourceId;
    
            $resourceId = count($items);
    
            for($x = 0; $x <= $resourceId-1; $x++){
    
                echo $items->videoId;
                echo "<hr />";
            }
    
        }
    

    【讨论】:

      猜你喜欢
      • 2016-04-20
      • 2017-04-05
      • 2019-08-01
      • 2016-10-04
      • 1970-01-01
      • 2016-08-25
      • 2014-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多