Tube Nations Tube Nations - 4 months ago 8
SQL Question

Detect if a youtube channel exists anymore & don't display if it gives Error?

So, after making a new youtube page, I noticed that some of my current users who have linked their youtube channels via youtube API and into our database, some of those users channels now give Error, where they no longer exist.

So I am basically creating the subscribe buttons from this code in an echo in my function.

<div class="g-ytsubscribe" data-channelid="'.$youtube_info['channel_id'].'" data-layout="full" data-count="default" data-onytevent="onYtEvent"></div>

So as you can see, I fetch that data from my database and it then contacts youtube to fetch that channel info. But some of my users channels now no longer exist, so I wondered if there was a way to detect this? and then to not display that particular user from being displayed at all?

so my query is this for the function.

$query = "SELECT user_id, yt_channelTitle, channel_id FROM points WHERE channel_id !='' AND yt_channelTitle != '' ";
$query .="ORDER BY channel_id DESC LIMIT " . ($objectsPerPage*2) . " OFFSET " . $_SESSION['last_record'];

I mean I was maybe thinking accross the lines of some type of maybe str_replace? method perhaps? but then it would be a question of what is it detecting the word
because that is what gets displayed in the youtube button instead of the channel subscriber count and profile image, it just shows a red icon with Error.?? I am open to ideas :)



I just wanted to post an answer to my question, and say I sorted a workaround out to this issue.

I basically just created a section in our admin section where we can now just easily edit the channel_id very easily, and made it blank. :)

So basically I just made a function for it :) so now all I need to do is click the link and it takes me to their channel. For ease of access :)

I will probably look into a automatic method, if it is needed, but this is sufficient for now.