Problem/Motivation

YouTube has released a new API, disabling the previous APIs, breaking the code.

Proposed resolution

Adapt the code for the last API usage.

Remaining tasks

Apply the patch and commit!

Original report

Since yesterday i get this video in my Youtube Channel Block.
https://youtube.com/devicesupport
"Youtube is upgrading to a newer version, which is not supported by this device or app. To learn more and see where you can watch YouTube, visit www.youtube.com/devicesupport"

Comments

sokrplare’s picture

Category: Support request » Feature request
Priority: Normal » Critical

Looks like v2 of the YouTube API has been fully deprecated (http://youtube-eng.blogspot.com/2014/03/committing-to-youtube-data-api-v...) and this module would need to switch to v3 (https://developers.google.com/youtube/v3/) to continue working.

michel3’s picture

subscrive problem. an update in works?

fadeslayer’s picture

I encountered the same problem, I temporarily switched to custom block with iframe embed, waiting for the problem solution.

manmando’s picture

same problem :P

markusgerlach’s picture

I got a message today its saying:

Could not fetch videos from youtube channel.

markusgerlach’s picture

Someone planning to provide a Youtube API v3 version of this module?

just.andy.shilton’s picture

Hi all,

Like you I came across the same "device support" message and realised what was going on. I'm not the module maintainer but I'm working on a fix it, in good Drupal spirit, sharing here seems to be the best place to post what I've found and what I'm working on.

The Issue
In short, the old YouTube API v2 has been deprecated. You can see that here: https://developers.google.com/youtube/2.0/developers_guide_protocol It was deprecated in March 2014 and switched off April 2015.

The new API v3 does what we need it to, but it does require you to setup a developer account with Google and get an API key.

Findings so far to include in the patch
There is a JSON feed available, if you have an API key. To obtain an API key, you will need to follow the instructions here: https://developers.google.com/youtube/v3/getting-started

In short: Get a google account, goto the Developers Console here https://console.developers.google.com/project , create a Project, under APIs, enable the YouTube Data API, then under Credentials Create a new API key. Grab this key cause we'll need it

Note: The module needs extending to store this API key

Finding the right feed
The new API can be used to to find the upload feed ID using the following logic (I'm going to use BCfm's YouTube channel as the example here because it is the feed I'm working on).
Grab the URL of the channel: https://www.youtube.com/channel/UClQzIwSpYAM2ZnelpiszXKw/feed
Extract the channel ID: UClQzIwSpYAM2ZnelpiszXKw
Make a call to the YouTube APIv3 to get the "uploads" playlist ID by calling the following:
https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UClQzIwSpYAM2ZnelpiszXKw&key={YOUR API KEY}
You'll notice the id is used in the call, along with your API key.
In the returned feed, you will get

"relatedPlaylists": {
     "uploads": "UUlQzIwSpYAM2ZnelpiszXKw"
    },

You can now use the ID for uploads to list them. The API paginates the results with a maximum of 50 per page.
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUlQzIwSpYAM2ZnelpiszXKw&key={YOUR API KEY}&maxResults=10
If there are more results than ten, a "NextPageToken" is given (and likewise, when paging you get a "PreviousPageToken"). Appending this to the end of the feed moves the page. Add"&pageToken={NextPageToken}" to the end to move pages.

The result is a JSON feed with all the details we need to display the YouTube videos.

I'm working on patches, but anyone else who is, please post too. Soon as I have a working patch I'll add it here.

Current Thoughts

  1. Add variable to store API key
  2. Alter the .module file to use JSON instead of simplexml (line 100)
  3. Alter the tpl file to use the latest embed code from YouTube
just.andy.shilton’s picture

StatusFileSize
new7.76 KB

Ok, sorry, it took me a while to figure out how to make a patch file. This is also the first time I've done this so if I'm doing this wrong, please don't get mad, I'm just trying to help.

Attached is a patch file for testing. I've tested it with a few feeds and it seems to be working ok.

The biggest changes - you'll need a Google API Key and this patch uses the channel ID (from the URL) instead of the username.

sokrplare’s picture

Status: Active » Needs review

Looking super promising - thanks for putting the work into this @d33jay!

A few minor items for feedback...
1) Might be worth doing some !empty() checks before jumping down to data deep in the array so we don't get bad errors if the format ever changes - for example something like:

  if ($channeljson->code == 200){
    $channel_data = drupal_json_decode($channeljson->data);
    if (!empty($channel_data) && !empty($channel_data['items']) && ...) {
      $uploads_id = $channel_data['items'][0]['contentDetails']['relatedPlaylists']['uploads'];

2) Using sprintf() to set the $path variable would be a bit cleaner.

3) Spacing looks like it uses 4-spaces to indent instead of Drupal standard of 2 spaces.

4) Oh, and if you want to know the standard patch naming conventions see step 11 in https://www.drupal.org/node/707484

Like I said all minor but figured if you want feedback here it is! Very thankful you did the heavy lifting on this! Marking as "Needs Review" instead of "Needs Work" since none of these issues are show stoppers so lets get some folks trying it out!

just.andy.shilton’s picture

@covenantd Thanks for the feedback. I had a feeling their might be a few things as I did it in a hurry this afternoon. Didn't know there was a patch naming standard either. Will make sure I use that in future.

I'll try and add the changes in if I get time tomorrow.

opstao’s picture

The same error is displaying for users of the Media: Youtube module when Youtube Channel and/or Youtube Channel Block is not also being used.

markusgerlach’s picture

This patch work for me.

First i try to add the patch throw shell with

/web/sites/all/modules/youtubechannel$ patch -p1 < youtubechannel.patch
but i got this error

(Stripping trailing CRs from patch; use --binary to disable.)
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git sites/all/modules/contrib/youtubechannel/README.txt sites/all/modules/contrib/youtubechannel/README.txt
|index ebfe230..4035a92 100644
|--- sites/all/modules/contrib/youtubechannel/README.txt
|+++ sites/all/modules/contrib/youtubechannel/README.txt
--------------------------
File to patch:

then i edit the modul code and it works.

thx

novatek’s picture

The patch #8 works for me, thx!

nupeossa’s picture

Hello markusgerlach!

I have the same error as you,
You can edit the code explain how exactly?
exactly where in the module?
Thanks in advance

sokrplare’s picture

See https://www.drupal.org/patch/apply - if you aren't familiar with Git, look at the links for how to apply on Windows/manually at the bottom of that article.

casiflis_’s picture

Which kind of API we have to use? Server API KEY; Navigator Key, Android, iOS..i patched the module and follow the instructions, but my module shows the same "devicesupport".

casiflis_’s picture

If i use the both links by d33jay
https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id={MY CHANNEL ID}&key={YOUR API KEY}

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlis...{MY PLAYLIST ID}&key={YOUR API KEY}&maxResults=10

I obtain the videos list, but when I put the Key and the CHANNEL ID on the Module configuration, i cant get the videos.

Maybe one of you who the patched worked can upload the entire module patched for testing.

just.andy.shilton’s picture

@castiflis2 if you are seeing the old feed you either haven't applied the patch correctly or you need to flush your cache to ensure your Drupal installation uses the new code.

The code in the patch is a completely different feed which uses JSON. The old feed didn't so if you see the old feed, see the instructions that covenantd posted for applying patches. For windows users I have noticed it often doesn't read the UPPERCASE of the readme file when applying the patch. The guides should help you get around this, but you could alternatively comment out the patching of the readme file while testing. I only updated the instructions.

For finding the correct API key, use the following steps:

1) Sign up to Google at https://accounts.google.com
2) Log in to your developer console at https://console.developers.google.com/project
3) Create a project and give a name (eg myyoutubechannel). Note, it takes a minute or two for the project in initiate. Just wait.
4) Under APIS & Auth->apis Click on YouTube Data API, then click ENABLE at the top
5) Under APIS & Auth->credentials Click Create New Key. When asked, click on Browser Key
6) OPTIONAL - You can restrict which websites can use this key by adding the domains you want to use the youtubechannel module with. For testing it probably isn't necessary but it would be good security to restrict the domains for live sites as your API key is exposed as part of the calls the module makes to YouTube. If the key works on any domain someone else could use it and use up your credits. You can edit this list later by coming back to this location and clicking "edit allowed referers".

This is the API key you need for this module. It is now a requirement to use the Youtube data API. (Unless someone wants to write an OAUTH version?).

casiflis_’s picture

@d33jay I have a patched module. @novatek sent me a patched module. (Thank you!)

I have the correct API and correct Channel ID, but I received a message saying "Please configure this section in the admin page".

I dont know where the problem is located, now i have this message.

Notice: Undefined offset: 0 en youtubechannel_getview() (line 105 de /home/myweb/www/sites/all/modules/youtubechannel/youtubechannel.module).

Steps I've done.

1) Edited manually the module and now i use a static link for hook the videos (with API kay and playlist), but the web shows the message below, the offset: 0 on that line.

just.andy.shilton’s picture

@Castiflis2 could you post your YouTube channel ID, or send it to me privately? I can have a look at the difference then and see what is going on.

David Hernández’s picture

Title: https://youtube.com/devicesupport video in Youtube Channel Block » Upgrade Youtube Channel module to support the new V3 API
Category: Feature request » Bug report
StatusFileSize
new7.13 KB

Here is a reroll of d33jay patch at #8. The previous patch wasn't applying due to being done on a git repository that wasn't a clone of the youtubechannel git repo.

I also have done some small changes so the code complies with the Drupal Code Standards: https://www.drupal.org/coding-standards

David Hernández’s picture

StatusFileSize
new6.89 KB

Ok, there were some errors on the patch. Here is the correct one.

casiflis_’s picture

Patch #22 worked fine to me.

Thank you guys for the time you inverted in this.

nupeossa’s picture

Tank you David Hernández
Finally i can patch my module.

bendev’s picture

patch #22 is working fine

thanks

just.andy.shilton’s picture

@David Hernández Thank you mate. Bit new to patching and the like. Appreciate ya help :)

David Hernández’s picture

@d33jay, no problem! Here is the documentation where explains how to create patches properly: https://www.drupal.org/node/1054616

kow’s picture

Title: Upgrade Youtube Channel module to support the new V3 API » Can anyone attach the patched file?
Issue summary: View changes

Can anyone attach the patched file?

sokrplare’s picture

Title: Can anyone attach the patched file? » Upgrade Youtube Channel module to support the new V3 API
Status: Needs review » Reviewed & tested by the community
David Hernández’s picture

Issue summary: View changes

@kow, please, don't hide the files. If you don't know how to apply a patch, here is the documentation: https://www.drupal.org/patch/apply

Also, don't delete the information of the issue summary if you are not going to add new valuable information.

David Hernández’s picture

Issue summary: View changes
Rasti’s picture

I tried to patch it. i got this error :

user@domain.com[~/www/sites/all/modules/youtubechannel$ patch < 2474977-22-upgrade-to-api-v3.patch
patching file README.txt
patching file youtubechannel.admin.inc
patching file youtubechannel.info
Hunk #1 FAILED at 6.
1 out of 1 hunk FAILED -- saving rejects to file youtubechannel.info.rej
patching file youtubechannel.module

any one get same error.

David Hernández’s picture

@Rasti, can you try to patch it using git?

user@domain.com[~/www/sites/all/modules/youtubechannel$ git apply 2474977-22-upgrade-to-api-v3.patch

Another question, are you using the last version of the module? The patch needs to be applied to the last dev version.

ksi’s picture

@David Hernández

Thank you very much for your work. With the patch the playlist (small video thumbs) is back again.
But the embedded player is gone. The URL in iframe 'src' attribute is correct, but there is no generated YT code in the iframe part.

Does anybody have an advice for me?

just.andy.shilton’s picture

@ksi I didn't change the iframe bit when I rewrote the code so it should just pull the new HTML5 player in. If it doesn't, firstly make sure you are getting videos - try another feed for example. Also check you have your width and height set.

If that still doesn't work, does it load in a different browser?

If it's still not working, could you post or private message me your channel ID and I'll have a look?

ksi’s picture

@d33jay

Thank you very much for the great work (have seen now, you did the changes) and for your answer.

I've found the reason:
In the JS file youtubechannel.js
the line
jQuery('#youtubechannel-frame').attr('src','http://www.youtube.com/embed/' + youtubeid);
is found. That does not work for HTTPS-sites. So the line has to be changed to:
jQuery('#youtubechannel-frame').attr('src','//www.youtube.com/embed/' + youtubeid);

Rasti’s picture

@David Hernández

I cant find the dev version. i applied the patch on: 7.x-2.1 tar.gz (9.53 KB) | zip (11.66 KB) 2014-Jun-22

when i use the git version on that one i get this
[~/www/sites/all/modules/youtubechannel$ git apply 2474977-22-upgrade-to-api-v3.patch
warning: youtubechannel.admin.inc has type 100644, expected 100755
error: patch failed: youtubechannel.info:6
error: youtubechannel.info: patch does not apply
warning: youtubechannel.module has type 100644, expected 100755

David Hernández’s picture

Assigned: Unassigned » David Hernández
Status: Reviewed & tested by the community » Needs work

@ksi, thanks for the update! I will provide a new patch soon.

@Rasti, that problem is caused because the permissions of the files of the module have changed. You can tell git to ignore those permissions with the next command:

git config core.filemode false

After that, you should be able to apply the patch.

If this doesn't work (I'm not really sure about that command), try to change the permissions to 755:

chmod 755 youtubechannel.admin.inc

You can also try to download the dev version of the module and then, applying the patch:

git clone --branch 7.x-2.0 http://git.drupal.org/project/youtubechannel.git

David Hernández’s picture

Assigned: David Hernández » Unassigned
Status: Needs work » Needs review
StatusFileSize
new7.36 KB

Ok, new patch uploaded to fix the error reported by @ksi at #37. That problem only affected users who are using the module under HTTPS.

just.andy.shilton’s picture

@ksi Ah yes, that would make total sense. Sorry, I'm wasn't testing on SSL for it to have shown up.
@David Hernandez, thanks for patching. I will give it a test on SSL this weekend if I can and feedback.

Rasti’s picture

@David Hernández

Thanks I download the version you gave me and i applied the latest patch.

But turn out the channel I am using wont accept it. i believe cause of the channel Id.

I tried with this : https://www.youtube.com/user/ancientsocieties (didn't work)
getting this error :
Notice: Undefined offset: 0 en youtubechannel_getview().....

but i tried with this : https://www.youtube.com/channel/UCPWQWav6BpPvtanCtloXkiw (worked fine)

just.andy.shilton’s picture

@Rasti - this patch requires that you use channel ID. It won't work with a channel name. When I started playing around with channel names it caused lots of errors, whereas the ID is exact. Make sure you setup your module using the channel ID and you should be fine.

Rasti’s picture

@d33jay

To whom may concern and have same issue I had. as @d33jay said this patch is only work with channel ID and User ID, not channel name or user name.

Therefore if you are on a channel or user page in youtube, that uses name instead of ID. here the way to obtain the ID.

View the source code of channel page or user page and find the "data-channel-external-id=" what ever come next to that is the ID.

just.andy.shilton’s picture

I did some searching and have found the following page that details the API calls to get the IDs of channels. It maybe possible to add this into the module. The biggest point to note though, as Google state on the page, is that not every YouTube channel has a unique username so if we add it in we'll need to be mindful of this.

https://developers.google.com/youtube/v3/guides/working_with_channel_ids

I'm testing the following : https://www.googleapis.com/youtube/v3/channels?key={YOUR_API_KEY}&forUsername={USER_NAME}&part=id

David Hernández’s picture

What @d33jay is propossing at #45 seems interesting, but I think it should be in a Feature request in a new issue.

arthitst’s picture

Thank you all
That 's work.

just.andy.shilton’s picture

Can also confirm I have it working on both SSL and non.

Would be good to get some more feedback from the rest of you so we can perhaps move it to RTBTC and perhaps get it into the module as the current version is useless now the old feed has gone.

Has anyone else managed to successfully test the patch?

spanners’s picture

Hello. I tried the above patch just by copying the patch file into the youtubechannel directory in modules and then "patch < 2474977-40-upgrade-to-api-v3.patch"

I get the following.

patching file README.txt
can't find file to patch at input line 18
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/js/youtubechannel.js b/js/youtubechannel.js
|index 9d99492..84eeaa1 100755
|--- a/js/youtubechannel.js
|+++ b/js/youtubechannel.js
--------------------------
File to patch:

I punch in js/youtubechannel.js and then I get...

patching file js/youtubechannel.js
patching file youtubechannel.admin.inc
patching file youtubechannel.info
Hunk #1 FAILED at 6.
1 out of 1 hunk FAILED -- saving rejects to file youtubechannel.info.rej
patching file youtubechannel.module

I checked the Youtube Channel admin settings and the new fields are there for API and Channel ID. I punch in the credentials I am certain are correct, but the published block just says "Please configure this section in the admin page".

I have added my website's address to the list of referrers on my API project.

Any help getting the videos displaying would be greatly appreciated. Have I patched the module correctly?

delmonij’s picture

StatusFileSize
new7.06 KB

I had good luck with 2474977-40-upgrade-to-api-v3.patch but need to save api usage on a busy site. This is just a tiny patch to the api urls. Thanks https://www.drupal.org/u/david-hern%C3%A1ndez for the real work!

This version had a typo fixed in next comment

delmonij’s picture

StatusFileSize
new7.06 KB
delmonij’s picture

StatusFileSize
new10.64 KB

This d6 version removes the "theme" functionality and is pretty much identical to to 7.x version.

eng_ismail’s picture

Hello. I tried the above patch.
the error i got ""Sorry, there are no videos available on this channel.""

delmonij’s picture

Try to edit the module settings to include your v3 api "youtube_id"(v3 UID) and set "channel_id"(channel ID) and then you may have to clear cache / boost cache.

You can find your channel_id by looking at the source of your "upload page" for this tag data-channel-external-id="UCjXfkj5iarKHJrhYfeF9ZGg"... If the problem continues please try to uninstall/reinstall the module

eng_ismail’s picture

@delmonji thank u bro it's work when i do it manually ,,,
but there's a problem that the API key is ACTIVE only one day and then will be inactive :( So , what i should to do ???
or i must billing before ?? is there another way to make it activate all the time ??

Thx in advance :D

eng_ismail’s picture

hello everyone,,
Please i need your help ,, i do all the step and add the patch ,, everything work fine on localhost machine
but when i upload these change on the server side it's not working and give me this message "Please configure this section in the admin page"
So, what i forget to do ??

Please help,

Thx in advance :D

David Hernández’s picture

@eng_ismail, my guess is that you haven't configured the module on the server. The configuration of the module is stored on the database, so just uploading the changes from your local machine is not enough.

eng_ismail’s picture

@david Hernandez , thx alot man for ur reply,
First, i remove the old " youtube channel module" on the server then upload the new one,
Second i put the path static "api_key" and "channel_id"

so, what i must to do on the database server to get it work ??

Thx bro in advance :D

David Hernández’s picture

@eng_ismail, just go to the administration page of the module ( admin/config/services/youtubechannel ) and configure it as you did on your local machine.

eng_ismail’s picture

@David Hernández, thx for ur reply,

I did as you send exactly and still the same message appear :(

And do all possible things and it's not working :(

Any help please

eng_ismail’s picture

@David Hernández good afternoon ;)
I can handle the error now it's come from the server side ,, i got this error message "Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?" and i contact the server manager and he told me he can't enable this extension because of the security issue .. and please note that the V2 of youtube api it was work fine so, do you think is there any other way to make it work ???

Thx in advance :d

just.andy.shilton’s picture

@eng_ismail - if you cannot use SSL from your server, try changing the YouTube URLs in the settings to NOT use SSL. To do this, change the HTTPS:// to HTTP:// This new module should support both now.

The YouTube API v2 is dead and the methods it used no longer valid so you need the new patches and to use API V3.

karbou’s picture

I have the same problem like @eng_ismail "Please configure this section in the admin page" but in localhost and in my server. I don't understand where is the probleme. I patch youtubechannel with this commande "patch -p1 < 2474977-22-upgrade-to-api-v3.patch, I had just one error with youtube channel.info at the line 10 but i add "configure = admin/config/services/youtubechannel" in this file.

Thanks for help

David Hernández’s picture

Please, don't hide the last patches as is the last version where people might be working.

karbou’s picture

Sorry it's not intentional

sothish’s picture

Thanks @delmonij, #54 works fine for me. Please find the attached files, Some more minor changes are added in this interdiff.

xenophyle’s picture

This patch worked for me, although for some reason I needed to apply it manually.

bendev’s picture

StatusFileSize
new8.22 KB

reroll patch to make it installable with drush make

nitinsp’s picture

Status: Needs review » Reviewed & tested by the community

2474977-66-upgrade-to-api-v3.1.patch #66 its working fine for me.

nitinsp’s picture

Status: Reviewed & tested by the community » Fixed

  • sothish authored fd2078e on 8.x-1.x
    Issue #2474977 by David Hernández, delmonij, sothish, andy.thomas,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

realEuph’s picture

I tried to install the patch in #66 to 7.x-2.1 after a clean download. I used the instructions at https://www.drupal.org/patch/apply (patch -p1 < 2474977-66-upgrade-to-api-v3.1.patch) [patch -p1 < 2474977-66-upgrade-to-api-v3.1.patch] when in the module's directory.

I get the following:

# patch -p1 < *.patch
patching file README.txt
patching file css/youtubechannel.css
patching file js/youtubechannel.js
patching file youtubechannel.admin.inc
patching file youtubechannel.info
Hunk #1 FAILED at 6.
1 out of 1 hunk FAILED -- saving rejects to file youtubechannel.info.rej
patching file youtubechannel.module
Hunk #2 FAILED at 11.
Hunk #3 succeeded at 38 (offset 11 lines).
Hunk #4 succeeded at 53 (offset 11 lines).
Hunk #5 succeeded at 74 (offset 11 lines).
Hunk #6 FAILED at 74.
2 out of 6 hunks FAILED -- saving rejects to file youtubechannel.module.rej

youtubechannel.info.rej

--- youtubechannel.info
+++ youtubechannel.info
@@ -6,3 +6,5 @@
 files[] = youtubechannel.admin.inc
 files[] = youtubechannel.module
 files[] = youtubechannel_videos.tpl.php
+
+configure = admin/config/services/youtubechannel

youtubechannel.module.rej

--- youtubechannel.module
+++ youtubechannel.module
@@ -11,12 +11,24 @@
 function youtubechannel_help($section) {
   switch ($section) {
     case 'admin/help#youtubechannel':
-      return t("Youtube Channel let's you have a complete video list from an sp
ecific user inside your site,
-        you only have to configure the dimensions and the username that you'll
use to feed the page.");
+      return t("Youtube Channel let's you have a complete video list of up to'
+        . ' 50 videos from a YouTube Channel. A Developer's API key is'
+        . ' required. See the readme.txt for how to obtain one.");
   }
 }

 /**
+ * Implements hook_permission().
+ */
+function youtubechannel_permission() {
+  return array(
+    'administer youtubechannel' => array(
+      'title' => t('Administer Youtube Channel'),
+    ),
+  );
+}
+
+/**
  * Implements hook_menu().
  */
 function youtubechannel_menu() {
@@ -27,7 +39,7 @@
     'description' => 'Configure the settings to be used for Youtube Channel.',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('youtubechannel_settings_form'),
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer youtubechannel'),
     'file' => 'youtubechannel.admin.inc',
     'type' => MENU_NORMAL_ITEM,
   );
@@ -42,8 +54,6 @@
   $blocks = array();
   $blocks[0] = array(
     'info' => t('Youtube Channel'),
-    'status' => 1,
-    'region' => 'sidebar_first',
   );
   return $blocks;
 }
@@ -65,7 +75,7 @@
  */
 function youtubechannel_theme() {
   return array(
-    'youtubechannel_videos_tpl' => array(
+    'youtubechannel_videos' => array(
       'variables' => array('vars' => NULL),
       'template' => 'youtubechannel_videos',
     ),
@@ -76,46 +86,60 @@
  * Function that build the Youtube videos as a Channel.
  */
 function youtubechannel_getview() {
-  $youtube_user = variable_get('youtubechannel_user', NULL);
+  $youtube_id = variable_get('youtubechannel_id', NULL);
   $max_results = variable_get('youtubechannel_video_limit', 5);
+  $api_key = variable_get('youtubechannel_api_key', NULL);

   drupal_add_css(drupal_get_path('module', 'youtubechannel') . '/css/youtubechannel.css');
   drupal_add_js(drupal_get_path('module', 'youtubechannel') . '/js/youtubechannel.js');

+  /**
+   * NEW API v3 feed
+   */
+  // First, let's fetch the channel feed to get the upload playlist.
+  $path = "https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id={$youtube_id}&maxResults=1&fields=pageInfo/totalResults,items/contentDetails/relatedPlaylists/uploads&key={$api_key}";
+  $channeljson = drupal_http_request($path);
+
+  // Check we got a proper response.
+  if ($channeljson->code == 200) {
+    $channel_data = drupal_json_decode($channeljson->data);
+    $uploads_id = $channel_data['items'][0]['contentDetails']['relatedPlaylists']['uploads'];
+
+    if (!empty($channel_data['items'])) {
+      // Now we have the uploads feed ID, let's grab the the actual video feed.
+      $path = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&}&maxResults={$max_results}&fields=pageInfo/totalResults,items/snippet(resourceId/videoId,title,thumbnails/default/url)&playlistId={$uploads_id}&key={$api_key}";
+      $playlistjson = drupal_http_request($path);
+      // Now, let's check that this also gives us a valid response.
+      if ($playlistjson->code == 200) {
+
+        $feed_array = drupal_json_decode($playlistjson->data);
+
+        // First, let's look in the feed and check there are some videos.
+        if ($feed_array['pageInfo']['totalResults']==0) {
+          return t("Sorry, there are no videos available on this channel.");
+        }

-  // Getting the video list.
-  $path = "http://gdata.youtube.com/feeds/api/users/{$youtube_user}/uploads?max-results={$max_results}";
-  $xmlfile = drupal_http_request($path);
-
-  if ($xmlfile->code == 200) {
-    $youtube_videos = simplexml_load_string($xmlfile->data);
-
-    $videos = array();
+        // Now let's iterate through our items.
+        $videos = array();

-    if ($youtube_videos->entry) {
-      foreach ($youtube_videos->entry as $key => $value) {
-        if (preg_match("/videos\/(.*)/", (string) $value->id, $match)) {
-          $youtube_id = $match[1];
-          $title = (string) $value->title;
+        foreach ($feed_array['items'] as $key => $value) {
+          $youtube_id = $value['snippet']['resourceId']['videoId'];
+          $title = $value['snippet']['title'];
           $image_variables = array(
-            'path' => "http://i4.ytimg.com/vi/{$youtube_id}/default.jpg",
+            'path' => $value['snippet']['thumbnails']['default']['url'],
             'alt' => $title,
             'title' => $title,
           );
           $thumb = theme('image', $image_variables);
-
           $videos[$youtube_id] = $thumb;
         }
-      }
-
-      $vars['width'] = check_plain(variable_get('youtubechannel_video_width', 200));
-      $vars['height'] = check_plain(variable_get('youtubechannel_video_height', 150));
+        $vars['width'] = check_plain(variable_get('youtubechannel_video_width', 200));
+        $vars['height'] = check_plain(variable_get('youtubechannel_video_height', 150));
+        $vars['content'] = $videos;

+        return theme('youtubechannel_videos', array('vars' => $vars));
+      }
     }
-
-    $vars['content'] = $videos;
-
-    return theme('youtubechannel_videos_tpl', array('vars' => $vars));
   }

   return t("Please configure this section in the !link", array('!link' => l(t('admin page', array()), 'admin/config/services/youtubechannel')));