如何检索youtube频道(PHP)的个人资料图片?

如何检索youtube频道(PHP)的个人资料图片?,php,json,image,youtube,channel,Php,Json,Image,Youtube,Channel,因此,我的页面通过youtube API连接youtube频道,并保存令牌等。。但是我没有找到任何代码示例来检索youtube个人资料图片 我在这里发现了去年的另一个帖子,有人用json纸条回答。情况如下: var json = new WebClient().DownloadString("http://gdata.youtube.com/feeds/api/users/"+YT_CHANNEL_NAME); string str = "thumbnail url='"; st

因此,我的页面通过youtube API连接youtube频道,并保存令牌等。。但是我没有找到任何代码示例来检索youtube个人资料图片

我在这里发现了去年的另一个帖子,有人用json纸条回答。情况如下:

var json = new WebClient().DownloadString("http://gdata.youtube.com/feeds/api/users/"+YT_CHANNEL_NAME);
    string str = "thumbnail url='";
    string ImagePic = json.Substring(json.IndexOf("thumbnail url") + str.Length);
    if (ImagePic.Contains("'"))
    {
        ImagePic = ImagePic.Remove(ImagePic.IndexOf("'"));
        ImageChannel.ImageUrl = ImagePic;

    }

我在JSON方面没有任何经验,也不知道这是否仍然适合我,以及如何在我的PHP代码中实现它

这是如何用PHP从youtube频道获取个人资料图片

1、下载php api

2,拿你的

4、您还需要频道ID,如果是您自己的帐户,您可以从

这是php代码

<?php

$DEVELOPER_KEY = 'YOUR_KEY';

// Call set_include_path() as needed to point to your client library.  
require_once('/path/to/api/src/Google_Client.php');
require_once('/path/to/api/src/contrib/Google_YouTubeService.php');

$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);

$youtube = new Google_YoutubeService($client);
$htmlBody = '';
try {

    $channelsResponse = $youtube->channels->listChannels('contentDetails', array(
        'id' => 'CHANNEL_ID',
        'part' => 'snippet',
    ));


    //echo '<pre>';
    //print_r($channelsResponse);
    //echo '</pre>';
    $img = $channelsResponse['items'][0]['snippet']['thumbnails']['default']['url'];

    echo "<img src='$img'>";

} catch (Google_ServiceException $e) {
    $htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
    $htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
}
echo $htmlBody;
?> 

它是以常规数组返回的,文档是,您也可以使用“中”或“高”而不是“默认值”

根据文档,您确实可以访问配置文件映像:其次,这是服务器端JavaScript,Node.js。你不能直接翻译它,它是太不同的脚本语言与自己的实现。话虽如此,您是否研究过php youtube api框架?如果你想下载它,也可以在这里检查答案以获得用户:是的,新的YouTube API有点麻烦。超级健谈。