• Hello, everyboby!

    I have got a problem during my WP-site customization, and Ill be very thankful if you help with it. The matter is that my site is meant to show in some cases a youtube channel info of an author (they are a lot actually), but all my searches of how I can realize it on my site were without result. Im ready to buy some plugin that will fit. Can you tell me (or write it here), please, how I can fix the problem, that is to say how I can retrieve the youtube channel stats of a certain user on my site pages. I am only in need of a number of subscribers and views from the channel start.

    Thank you for you possible help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,

    you can use YouTube Api to do that, along with PHP:

    PHP:

    function elh_subs_count($username) { 
    
    $xmlData = file_get_contents('https://gdata.youtube.com/feeds/api/users/' . strtolower($username));
    $xmlData = str_replace('yt:', 'yt', $xmlData); 
    
    $xml = new SimpleXMLElement($xmlData); 
    
    $subs = $xml->ytstatistics ['subscriberCount']; 
    
    return($subs); 
    
    }
    function elh_view_count($username) { 
    
    $xmlData = file_get_contents('https://gdata.youtube.com/feeds/api/users/' . strtolower($username));
    $xmlData = str_replace('yt:', 'yt', $xmlData); 
    
    $xml = new SimpleXMLElement($xmlData); 
    
    $views = $xml->ytstatistics['totalUploadViews']; 
    
    return($views); 
    
    }

    throw the above codes in your functions.php file or making a plugin.
    and, use the following tags to retrieve the info you are seeking:

    Subscribers count:
    <?php echo elh_subs_count('channel_username'); ?>
    Views count:
    <?php echo elh_view_count('channel_username'); ?>

    I have tested it, I have put the following code in my footer.php

    <p>
    Subscribers count:
    <?php echo elh_subs_count('dvlotteryforum'); ?>
    Views count:
    <?php echo elh_view_count('dvlotteryforum'); ?>
    </p>

    and it returned:

    Subscribers count: 190Views count: 27237

    If it is working, and you are looking forward doing more like making this dynamic for users to type their channel usernames via a panel, then simply reply.

    Thread Starter Scrooge3

    (@scrooge3)

    Hello, Sam Elh!

    I don`t know how to thank you, because I have got no answer for this question wherever I asked for it.

    Now Im still in trouble. Ive inserted the text above in my functions.php, but how to make shortcodes out of these tags:
    =============================
    Subscribers count:
    <?php echo elh_subs_count(‘channel_username’); ?>
    Views count:
    <?php echo elh_view_count(‘channel_username’); ?>
    =============================

    I suppose you can make a plugin and commercialize it with such knowledge of PHP. The demand for that will be very high and you can get money for your skills.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @elhardoum? I’ve deleted your offer for contact off of the forum. That’s not permitted here and please do not do that again.

    https://codex.www.ads-software.com/Forum_Welcome#The_Bad_Stuff

    I suppose you can make a plugin and commercialize it with such knowledge of PHP. The demand for that will be very high and you can get money for your skills.

    @scrooge3 If you require that level of assistance then please consider posting to https://jobs.wordpress.net/ instead.

    I’m not closing this topic down but please refrain from heading in that direction topic wise.

    Jan,

    Apologize. I have never been to that page.

    Thanks for the alert mod.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Not a problem and I thank you for understanding.

    Not a problem and I thank you for understanding.

    Jan, you are the one we should thank, keeping these forums a better place..

    Scrooge3, You are welcome.

    I suppose you can make a plugin and commercialize it with such knowledge of PHP. The demand for that will be very high and you can get money for your skills.

    I am going to create a quick free plugin and provide a link pointing to github gist in brief delays.

    Thank you.

    Scrooge3, I wonder if you are still interested.. I have made a plugin ( Youtube information widget ) which is the first one I make ( considering that I am new to PHP ), and I have just uploaded it to github.

    This plugin allows you to embed information about your YouTube channel, including the last uploads, popular uploads, channel statistics including subscribers count, views count, and the about information, and also, a subscribe button next to your channel icon. comes with a settings page where you can control your output..

    You can download it here: https://github.com/elhardoum/youtube-information-widget

    And it is still in beta mode and will request an upload to WP plugin repository once I am done with it.

    You can edit it to fit your requirements, and I am here to help ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Youtube channel information’ is closed to new replies.