youtube / api-samples

Code samples for YouTube APIs, including the YouTube Data API, YouTube Analytics API, and YouTube Live Streaming API. The repo contains language-specific directories that contain the samples.
5.43k stars 2.97k forks source link

Is ChannelTopicDetail now depricated? #178

Open SheikMain opened 6 years ago

SheikMain commented 6 years ago

I've had been utilizing the api for sometime for my web application. I've never had any issues with my function to pull my users topic details.

Yesterday, an issue popped up prompting the following error:

Error Class 'Google_Service_YouTube_ChannelTopicDetails' not found - /wp-content/themes/freelanceengine/vendor/google/apiclient/src/Google/Model.php:231

Here is the function snippet parsing topicDetails:

`<?php

function youtubeProfileDataArray($channel_id){

$client = getClient(); 
$service = new Google_Service_YouTube($client);
$part ='topicDetails,statistics, topicDetails'; 
$channel_id=array('id'=>$channel_id);

$isChannelId = username2ChannelId($channel_id);
$isChannelId = isChannelId($channel_id);

$response = $service->channels->listChannels($part,$channel_id); 
$topic = $response->items[0];
return $topic;
$channel_id = $response['items'][0]['id'];

$topicId_json= $response['items'][0]['topicDetails']['topicIds']; //returns json array for just topicIds

foreach ($topicId_json as $key=>$value){  //fills topicIdArray, topic id is the key. 
    $topicId=$value;
    $topicIdArray[]=$topicId;
}

$viewsPerVideoArray = viewsPerVideoArray($channel_id, $service); //pass service to reduce another client request
$averageViews   = round(array_sum($viewsPerVideoArray)/count($viewsPerVideoArray));
$averageViews= (string)$averageViews;
$youtubeProfileDataArray = array(
    "channel_id"            =>  $channel_id, 
    "title"                 =>  $response['items'][0]['snippet']['title'], 
    "subscribers"           =>  $response['items'][0]['statistics']['subscriberCount'], 
    "totalViews"            =>  $response['items'][0]['statistics']['viewCount'], 
    "totalVideos"           =>  $response['items'][0]['statistics']['videoCount'],
    "topicIdArray"              =>  $topicIdArray,  //sub Array
    "averageViewsPerVideo20"=>  $averageViews,
);
//session_write_close(); //— Write session data and end
return ($youtubeProfileDataArray);

};// end function

?>`

This has worked fine for quite a long time.

What's very odd is while debugging the error, I returned $response['items'][0] and it included everything we need, including topicDetails. I then tried simply parsing ['topicDetails'] from the response in the file I called the function and received the same error.

Is topicDetails now depricated or has anything changed?

Thank you.

SheikMain commented 6 years ago

One thing I forgot to mention, everything else we are parsing works fine such as $response['items'][0]['statistics'], it's only topicDetails that's causing problems.

AndyDiamondstein commented 6 years ago

The topicDetails.topicIds[] property is deprecated.

But the topicDetails part as a whole is not fully deprecated. And you might still see the topicIds property populated, but since it's deprecated, it could be removed at any time and I think your code shouldn't assume that it'll be present. Here's an APIs Explorer link that shows the topicDetails part for the GoogleDevelopers channel, where topicDetails.topicIds[] and topicDetails.topicCategories[] both have values: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list?part=topicDetails&forUsername=GoogleDevelopers&_h=1&